Game Development Reference
In-Depth Information
void OnGUI()
{
if (talking)
{
//Layout start
GUI.BeginGroup(new Rect(Screen.width / 2 -
conversationTextWidth / 2, 50, conversationTextWidth + 10,
dialogHeight));
//The background box
GUI.Box(new Rect(0, 0, conversationTextWidth + 10,
dialogHeight), "");
//The character name
GUI.Label(new Rect(10, 10, conversationTextWidth + 30,
20), currentConversationLine.SpeakingCharacterName);
//The conversation text
GUI.Label(new Rect(10, 30, conversationTextWidth + 30,
20), currentConversationLine.ConversationText);
//Layout end
GUI.EndGroup();
}
}
Like the navigation prompt in the previous chapter, we simply draw a GUI region, give it
a background texture with the box using the default style, and then show two labels: one
for the character who is speaking and one for the text of the conversation.
So, when the talking flag is set, Unity will know that it has to start drawing our con-
versation GUI on the screen.
To finish this off, we need to call the Coroutine from our public method, which other
scripts can use to start a conversation:
public void StartConversation(Conversation conversation)
{
//Start displaying the supplied conversation
Search WWH ::




Custom Search