From the course: Unity 4: 2D Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Displaying the time-limit bar

Displaying the time-limit bar - Unity Tutorial

From the course: Unity 4: 2D Essential Training

Start my 1-month free trial

Displaying the time-limit bar

Now that we've created our timer, let's look into how to actually use the GUI API immunity to display it on the screen so the player knows how much air they have left. We're going to go back into the meter script and add a few properties. Here, we've created texture references for the background of the bar. We also have one for the foreground of the bar which will be blue for the air, we also have an icon width so we know not to subtract from the icon bar more than the icon width. And we'll have an offset for where to place this on the screen. By default, the registration mark is going to be the upper left hand corner of the screen. Next, lets create a generic method we can use to draw a meter bar. Here, you can see our draw meter method requires an X and Y position for where it rendered on the screen. It will need a texture for the foreground, a texture for the background, and a percentage in order to manipulate the foreground texture to show the change in the bars width. Next, we'll…

Contents