COIN GAME


In the previous lessons, we have learned how to add, move, and rotate an object in Unity. We will now apply these concepts to create a simple game; COIN COUNTER GAME.

We need to import assets such as a ball (player), coin, robber (antagonist/challenge). After import, place the assets as shown.


Note that the robber's initial position must be out of the main scene.


ADDING SCORE TEXT

We want to display the players score in the game. In order to do that, we go to the Scene Panel, right click, select UI, and finally select Text.


A scene will be created named Canvas. Click Text under it, and from the Inspector Panel, write Score: as the text. Also, align the text in the upper center position of the canvas.



ADDING COMPONENTS FOR EACH ASSET

For the Score Text, we will add a script component containing the following code:


Make sure to add UnityEngine.UI library in your code since we are using a UI Component in the scene.

For the ball, we will add a script component for its controls - done previously here.

We will also add another script for the Score Counter of the ball player. 


Always check if your variables corresponds to the name of the components in the game.

Lastly, for the robber, refer to this blog to set its initial and next position. Adjust the speed in the Inspector Panel after the script has been added and assigned. In this example, we used 5 as the speed.

And we're done, click play and the game should be like this. Notice how the score counter works.




Comments