Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 2018 Cookbook

You're reading from   Unity 2018 Cookbook Over 160 recipes to take your 2D and 3D game development to the next level

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher
ISBN-13 9781788471909
Length 794 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Matt Smith Matt Smith
Author Profile Icon Matt Smith
Matt Smith
Francisco Queiroz Francisco Queiroz
Author Profile Icon Francisco Queiroz
Francisco Queiroz
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Displaying Data with Core UI Elements FREE CHAPTER 2. Responding to User Events for Interactive UIs 3. Inventory UIs 4. Playing and Manipulating Sounds 5. Creating Textures, Maps, and Materials 6. Shader Graphs and Video Players 7. Using Cameras 8. Lights and Effects 9. 2D Animation 10. 3D Animation 11. Webserver Communication and Online Version-Control 12. Controlling and Choosing Positions 13. Navigation Meshes and Agents 14. Design Patterns 15. Editor Extensions and Immediate Mode GUI (IMGUI) 16. Working with External Resource Files and Devices 17. Working with Plain Text, XML, and JSON Text Files 18. Virtual Reality and Extra Features 19. Automated Testing 20. Bonus Chapters 21. Other Books You May Enjoy

Creating a Fungus character dialog with images

The Fungus dialog system introduced in the previous recipe supports multiple characters, whose dialogs can be highlighted through their names, colors, sound effects, and even portrait images. In this recipe, we'll create a two-character dialog between Sherlock Holmes and Watson to illustrate the system:

How to do it...

To create a character dialog with portrait images using Fungus, follow these steps:

  1. Create a new Unity 2D project.
  2. Open the Asset Store panel, and Import the Fungus dialogue asset package (this includes the Fungus Examples, whose images we’ll use for the two characters).
  3. Create a new Fungus Flowchart GameObject by choosing menu: Tools | Fungus | Create | Flowchart.
  4. Display and dock the Fungus Flowchart window panel by choosing menu: Tools | Fungus | Flowchart Window.
  5. Change the name of the only Block in the Flowchart to The case of the missing violin.
  6. Create a new Character by choosing menu: Tools | Fungus | Create | Character.
  7. You should now see a new Character GameObject in the Hierarchy.
  8. With GameObject Character 1 – Sherlock selected in the Project panel, edit its properties in the Inspector:
    • Rename this GameObject Character 1 – Sherlock.
    • In its Character(Script) component, set the Name Text to Sherlock and the Name Color to green.
    • In the Inspector, click the Add Portrait button (the plus sign "+"), to get a "slot" into which to add a portrait image.
    • Drag the appropriate image into your new portrait image slot (in this screenshot, we used the "confident" image from the Sherlock example project: Fungus Examples | Sherlock | Portraits | Sherlock):
  1. Repeat steps 6-8 above to create a second character, John, using Name Color = blue, and Portrait Image = annoyed.
  2. Select your Block in the Fungus Flowchart, so you can add some Commands to be executed.
  3. Create a Say command, for Character 1 - Sherlock, saying Watson, have you seen my violin? and choose the confident portrait (since this is the only one we added to the character):
  1. Add a second Say command, this time for Character 2 – John, saying No, why don't you find it yourself using your amazing powers of deduction.. and choose the annoyed portrait:
  1. Run the scene you should see a sequence of statements, clearly showing who is saying both with (colored) name text AND the portrait image you selected for each Say command (after Sherlock’s text has finished appearing, click the box to start John’s sentence).

How it works...

You have created a new Unity project with the Fungus asset package.

You have added a Fungus Flowchart to your scene, and also added two characters (each with a text color and a portrait image).
For the Block in the Flowchart, you added to Say commands, stating which character was saying each sentence, and which portrait to use (if you had added more portrait images, you could select different images to indicate the emotion of the character speaking).

There's more...

There are some details you don't want to miss.

Data-driven conversations

Fungus offers a data-driven approach to conversations. The character and portrait (and facing direction, and movement onto-off the stage, and so on) can be defined through text in a simple format, using the Say command’s Narrative | Conversation option. This recipe’s conversation with portrait images can be declared with just two lines of text in a Conversation:

Sherlock confident: Watson, have you seen my violin?
John annoyed: No, why don't you find it yourself using your amazing powers of deduction...

Learn more about the Fungus conversation system on their documentation pages: http://fungusdocs.snozbot.com/conversation_system.html.

You have been reading a chapter from
Unity 2018 Cookbook - Third Edition
Published in: Aug 2018
Publisher:
ISBN-13: 9781788471909
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime