Game Development Reference
In-Depth Information
length, and then divides it by the maximum amount of health. All of these are vari-
ables that we've set to 100 , but can be modified to make the bar bigger or smaller.
Level counter
Our level counter will be used to show the player's current level. It's a simple yet
gratifying GUI element for the player. We'll only need one variable for the counter:
public int currentLevel = 1;
public GUIStyle myStyle;
We'll use currentLevel to show the player's current level. The GUIStyle variable
will be used to access the properties of our GUI label. To draw this on the screen,
we'll use a GUI label; add this line of code to the OnGUI() function:
GUI.Label(new Rect(Screen.width/2 + 15,
Screen.height/2 + 335, 30, 30),
currentLevel.ToString(), myStyle);
What this line of code does is draw the currentLevel variable on our screen,
between the two sets of buttons.
In the Start() function, add this line of code at the end:
myStyle.fontSize = 36;
We add this so that we can edit the size of the label font.
Creating an experience counter
The experience counter will show the player how much experience they earned as
well as how much more experience is left until they gain a new level. To show this,
we will use two GUI boxes: one for the player's current experience amount and the
other for the total amount of experience possible.
Search WWH ::




Custom Search