Unity 2018 Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

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).