Game Development Reference
In-Depth Information
Building a basic conversation system
In order for our conversation assets to be of any use, we need a mechanism to play these
conversations on the screen and have the user interact with them (if that's how your game
rolls). For this, we need another manager that will take in conversations from characters
and display them on the screen. If we had any logic, branching, or decisions in our con-
versations, it will handle those too.
Now, there are two basic approaches that we could take with the conversation system: one
being reactive (where we use a messaging system to notify the manager that a conversa-
tion needs to take place) and one being just a utility (where scripts can request for a con-
versation to take place). Both are valid approaches, and it really comes down to personal
preference as to which one you want to implement. To keep things simple, let's create the
basic utility first and then point out where it can be enhanced.
The manager
If we create our conversation manager as we did before with the messaging manager, we
start with the simple singleton framework. However, we will lean on one of the great ex-
amples from Unity Wiki as our base.
In the sample project under Assets\Scripts\Classes , you will find a
Singleton class that was sourced from http://wiki.unity3d.com/index.php/Singleton .
This simply saves us time and code while creating singleton objects for use in our games
and ensures they always have the same consistency.
With this in place, we can define our Conversation manager quite simply. Create a
new C# script in Assets\Scripts named ConversationManager and replace its
contents with the following code:
using System.Collections;
using UnityEngine;
public class ConversationManager :
Singleton<ConversationManager >
{
//Guarantee this will always be a singleton only -
//can't use the constructor!
protected ConversationManager () {}
Search WWH ::




Custom Search