Game Development Reference
In-Depth Information
• Choices
• The position of chat
The more you look at it, the more you can dream about what you want to include. You just
need to remember the
KISS
principle (
Keep it simple, stupid
), that is, start small and
then build on it.
So, create a new C# script, name it
ConversationEntry
in
Scripts\Classes
,
and populate it with the following code:
using UnityEngine;
[System.Serializable]
public class ConversationEntry {
public string SpeakingCharacterName;
public string ConversationText;
public Sprite DisplayPic;
}
This gives us just the basics for our conversation system with regards to who's speaking,
an optional picture that can be displayed in the conversation, and most importantly, the
conversation text to be displayed.
We also tag this class with the
System.Serializable
code attribute so that the Un-
ity serializer knows what to do with it.
Saving and serializing the object for later
With our core conversation entry object generated, we can start to store the conversations
in the
.asset
files for use in our game and also make it possible to create the conversa-
tions outside of Unity if you wish.
As a conversation is (usually) more than just an opening line, we need a management ob-
ject that will support several lines/entries of the conversation and a couple of switches to
denote whether the conversation has already been played. This way, if you have multiple
conversations configured for a character, it will simply play the next conversation and not
repeat itself. You could just track this on the object where you attach the conversations to,
but this is cleaner.