
Unity Game Development Blueprints
By :

One of the most important things to do in a game is reward the player and give them a sense of progression. For now, let's reward the player with a score we will display for them and also let the player know exactly which wave he is on. Perform the following steps:
If you are using the Unity 4.6 beta or higher versions, instead of creating the object in this way, you will need to select GameObject | Create Empty to create an empty object. Once you've done that with the object selected, then click on Component | Rendering | GUIText to add the component there.
Score Counter
. Under the GUI Text component, change the Text to Score: 0
. After that, change the Position of Transform to (0
, 1
, 0
) to put it on the left-hand side of the screen.GUI elements are placed in viewport space, which means that the space of the GUI is a value from (0
,0
) in the bottom-left corner to (1
,1
) in the top-right corner.
10
, -10
) to move it 10 pixels toward the right-hand side and 10 pixels down. Note that Pixel Offset uses pixel space. Have a look at the following screenshot:OSP-DIN
and Font Size to 25
.The font used in this project was created by the OSP Foundry. For more information about their stuff check out http://ospublish.constantvzw.org/foundry/.
Waves Counter
, and change its text to Wave: 0
.1
, 1
, 0
). Then set Anchor to upper right
and Pixel Offset to (-10
, -10
). Have a look at the following screenshot:GameController
class. Inside, we need to create some new variables as follows:// The values we'll be printing private int score = 0; private int waveNumber = 0; // The actual GUI text public GUIText scoreText; public GUIText waveText;
public void IncreaseScore(int increase) { score += increase; scoreText.text = "Score: " + score; }
The +=
operator will take the current value and add the right-hand side's value to it.
EnemyBehaviour
component. After the controller.KilledEnemy()
line, add the following line:controller.IncreaseScore(10);
GameController
class after the if(currentNumberOfEnemies <= 0)
line, add the following lines:waveNumber++; waveText.text = "Wave: " + waveNumber;
The ++
operator will take the current value of a number and increment it by 1.
And with that, you can see that everything is working together, killing enemies rewards points, and killing all the enemies in a wave triggers the next wave to start!
Change the font size
Change margin width
Change background colour