Monday, 15 March 2010

Starting the HUD

Now that the driving mechanics (minus the small bugs) and the waypoint system are down, I can now begin to make a start on the HUD. With the waypoint implementation still fresh in my head, I decided to begin with showing the number of laps the user has completed on the screen.

In the waypoints script, I have a static variable names NoLaps. This is the variable I am using to count the number of laps the players has driven round the course. In order to print this onto the screen, I need to introduce a GUIText into the scene.

After adding the GUIText, I needed to edit a few parts of the Waypoints script to print the variable 'NoLaps' to the GUIText. The first thing to do was to add a new variable.

var lapDisplay : GUIText;
This sets up a variable of type GUIText. Then I needed to create an update method and add a line of code to pass this new GUIText variable the interger value of the 'NoLaps' variable.

function Update () {
lapDisplay.text ="Lap " + NoLaps + "/5";
}

This line is pretty much self explanatory. It passes the NoLaps variable as well as some useful HUD text to the text component of the GUIText variable. All that is left is to Assign the GUIText game object to the lapDisplay variable in the script.

No comments:

Post a Comment