Adrian Joshua F. Esguerra
Rena Escora
BS-EMC2A
Activity #4: How to create a simple coin counter and
How to increase and decrease a coin in your Unity game
1. The 1st thing that you need to do is to add a "UI". To do that, Right click the hiearchy, click the "UI" and after that click the "Text".
2. After you did that, You will see the "Canvas" and the "Text" beneath it on the hiearchy column.
* In my case, I named the "Text" as "Score Text".
3. If you double click the "Canvas", You will see a scene view just like what you see on the main camera. Next is edit the text on the inspector and type the word "Score". After that, put it on the Top side center of the canvas.
4. Next is you need to create a Script that you will put on the "Score Text". Right click on the assets column, Click "Create" and click "C# Script". Name the Script as "Score".
5. Click the "Score" Script and write type this code on it and save it.
* Codes for Score
6. After you saved the Code, Drag the Script on the "Score Text".
7. The Text "Score" must have the number "0" beside it and that will be your Score or coin counter. "0" because you still don't have any Score yet.
8. The next thing that you need to do is to add the objects that will serve as your coins.
* In my case I added the Gems as my Coins.
9. Next is you need to put a "CircleCollider2D" Component on the coins and check the "Is Trigger" on it so that the object will disappear once you hit it.
10. Next is you need to double click and update the "Move" Script that you've put on your "Player". After you double click it, Add these Codes on it.
* These are the codes that will add a point on the gems once you hit it.
The Score that will be added depends on what number you put on it.
* You must put the exact name of the Gem object on this code.
11. The Score or Coin Counter must be add a point once you hit any of the gems.
12. Next is you need to add the object that will serve as the enemy or in other words, the object that will decrease your score once you hit it.
* These are the codes that will Minus/Decrease a point on your score once you the hit the enemy. The Score that will be Decreased depends on what number you put on it.
* You must put the exact name of the enemy object on this code.
13. The Score or Coin Counter must be Decrease a point once you hit any of the Enemy.

















Comments
Post a Comment