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:
Creating a Fungus character dialog with images
How to do it...
To create a character dialog with portrait images using Fungus, follow these steps:
- Create a new Unity 2D project.
- 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).
- Create a new Fungus Flowchart GameObject by choosing menu: Tools | Fungus | Create | Flowchart.
- Display and dock the Fungus Flowchart window panel by choosing menu: Tools | Fungus | Flowchart Window.
- Change the name of the only Block in the Flowchart to The case of the missing violin.
- Create a new Character by choosing menu: Tools | Fungus | Create | Character.
- You should now see a new Character GameObject in the Hierarchy.
- 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):
- Repeat steps 6-8 above to create a second character, John, using Name Color = blue, and Portrait Image = annoyed.
- Select your Block in the Fungus Flowchart, so you can add some Commands to be executed.
- 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):
- 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:
- 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.