Game Development Reference
In-Depth Information
Next, we need to calculate the scaling factor for the image for each conversation line, just
in case we are using different sizes of textures for each character in the conversation. So,
update the
DisplayConversation
Coroutine method with the following code:
IEnumerator DisplayConversation(Conversation conversation)
{
talking = true;
foreach (var conversationLine in
conversation.ConversationLines)
{
currentConversationLine = conversationLine;
conversationTextWidth =
currentConversationLine.ConversationText.Length *
fontSpacing;
scalledTextureRect = new Rect(
currentConversationLine.DisplayPic.textureRect.x /
currentConversationLine.DisplayPic.texture.width,
currentConversationLine.DisplayPic.textureRect.y /
currentConversationLine.DisplayPic.texture.height,
currentConversationLine.DisplayPic.textureRect.width
/ currentConversationLine.DisplayPic.texture.width,
currentConversationLine.DisplayPic.textureRect.height
/ currentConversationLine.DisplayPic.texture.height);
yield return new WaitForSeconds(3);
}
talking = false;
yield return null;
}
Lastly, we just need to update the
OnGUI
method to make space for the image using the
offset
method and then add it to the draw list as follows:
void OnGUI()
{