tiistai 20. syyskuuta 2016

Unity clicker - enemy and score

NAV16AP

1. jakso lukuvuonna 2016-2017

Now it’s time to create something to click. Import your enemy creatures to the unity project.

Bring enemy object to the scene. Create 2D box collider and FSM for the enemy. You’ll also need to make animation for enemy being hit. This can be done in many ways. You can scale the enemy when player clicks it, or move it slightly to the left or right. You can also have sprite sheet for the enemy and create animation in that way. Choose whatever method suits you best and remember to add animation component from add component button and select your animation as the animation in that component.


The FSM for enemy is quite simple. In the first state choose MOUSE DOWN from the system transition events. In the next state you’re going to add points with every click with action int add. Remember to create global int variable for your score. You’ll also need play animation action. Select the game object you’re using and the right animation for it.



You should show the score to the player so that feedback is given every time the enemy is hit. Create new label with NGUI named score and another label named score number. In the score label write score: in the text field. Choose the font you want to use in correct size and placement.
For the number label don’t write anything in the text field but make sure the label is placed after score label at the same height it is. You can also make the score label parent object to the number label by dragging the number label to the score label.



Lastly you’ll need to create FSM for the number. There will only be one state in which you use actions convert in to string and set property. One more variable is needed in string format. In the convert int to string action choose your score as the int variable and score_string as the string variable. For the set property you need to drag your UI label to the target object section. Choose text as the property and set value as your score_string value. Remember to put checkmarks to every frame boxes.


Ei kommentteja:

Lähetä kommentti