Game Development Reference
In-Depth Information
if (!talking)
{
StartCoroutine(DisplayConversation(conversation));
}
}
Adding more
There are two simple areas where we can take this further. We can use the sprite image
and the style that we specified in the conversation item.
Adding the image is fairly simple; we just need to create enough space to display the im-
age and then draw it.
Sadly, one of the areas that the new sprite system has not been merged with is the existing
GUI system. It still relies on textures and not sprites. We can still work with it, but it
means we have to select the sprite's texture from the spritesheet manually while drawing
images. To do this, we use the DrawTextureWithTexCoords GUI function.
Tip
A word of warning though: the DrawTextureWithTexCoords function uses scaled
coordinates while picking the section of the image you want to display. This usually trips
up developers as it is not very well documented. The coordinates in the Sprite object are
not scaled, so you have to convert them manually.
First, add a couple of properties to display the image using the following code:
//Offset space needed for character image
public int displayTextureOffset = 70;
//Scaled image rectangle for displaying character image
Rect scaledTextureRect;
The offset is to create space within our display region for the image, whereas the other
property is to hold the scaling information to indicate that we need to pick our sprite from
the spritesheet since the Unity system doesn't handle sprites.
Search WWH ::




Custom Search