Wednesday, September 17, 2014

Implement a timer counter for game by Using Time.deltaTime

To achieve this goal, I will give an example of TimeRemainDisplay:

Step 1: Get Resources:
Step 2: Create an Empty Object and name it as "TimeRemainDisplay". Write a script to control the Display.
Textures, labels, buttons and other UIs should be write under the OnGUI() function. 
From the line 15 to 19, the program is drawing the every number picture on the screen.

leftTime.ToString()[i] gets the ith number of leftTime. However it is a char, so we need to change it to String type. After that, use Parse function to change the value to an integer as the index of the Texture array.

GUI.DrawTexture() draws the UI on the screen, the first argument is a type of Rect which the first two value is the position and the last two are the width and height. The second argument is the object to draw.

Step 3 Drag the pictures to assign the texture array.
Step 4 Run the game.


No comments:

Post a Comment