Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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 UIs with the Fungus open source dialog system

Rather than constructing your own UI and interactions from scratch each time, there are plenty of UI and dialogue systems available for Unity. One powerful, free, and open source dialog system is called Fungus, which uses a visual flowcharting approach to dialog design.

In this recipe, we'll create a very simple, one-sentence dialogue, to illustrate the basics of Fungus. The following screenshot shows the Fungus-generated dialog for the sentence How are you today?:

How to do it...

To create a one-sentence dialog using Fungus, follow these steps:

  1. Create a new Unity 2D project.
  2. Open the Asset Store panel, search for Fungus, and Import this free asset package (search for Fungus and free).
  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. There will be one block in the Flowchart Window. Click on this block to select it (a green border appears around the block to indicate that it is selected). In the Inspector panel, change the Block Name of this block to Start:
  1. Each Block in a Flowchart follows a sequence of commands. So in the Inspector, we are now going to create a sequence of (Say) commands to display two sentences to the user when the game runs.
  2. Ensure that the Start block is still selected in the Flowchart panel. Click on the plus (+) button at the bottom section of the Inspector panel to display the menu of Commands, and select the Narrative | Say command:
  1. Since we only have one command for this block, that command will automatically be selected (highlighted green) in the top part of the Inspector. The bottom half of the Inspector presents the properties for the currently-selected Command, as shown in the following screenshot. In the bottom half of the Inspector, for the Story Text property, enter the text of the question that you wish to be presented to the user, which is How are you today?:
  1. Create another Say Command, and type the following for its Story Text property: Very well thank you.
  2. When you run the game, the user will first be presented with the How are you today? text (hearing a clicking noise as each letter is typed on screen). After the user clicks on the continue triangle button (at the bottom-right part of the dialog window), they will be presented with the second sentence: Very well thank you.

How it works...

You have created a new Unity project, and imported the Fungus asset package, which contains the Fungus Unity menus, windows, and commands, and also the example projects.

You have added a Fungus Flowchart to your scene with a single Block that you have named Start. Your block starts to execute when the game begins (since the default for the first block is to be executed upon receiving the Game Started event).

In the Start block, you added a sequence of two Say Commands. Each command presents a sentence to the user, and then waits for the continue button to be clicked before proceeding to the next Command.

As can be seen, the Fungus system handles the work of creating a nicely-presented panel to the user, displaying the desired text and continue button. Fungus offers many more features, including menus, animations, and control of sounds and music, the details of which can be found in the next recipe, and by exploring their provided example projects, and their websites:

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 $19.99/month. Cancel anytime
Banner background image