tiistai 13. syyskuuta 2016

Unity platformer - checkpoint

NAV15AP

1. jakso lukuvuonna 2016-2017

First you need to draw object that represents a checkpoint in your game. Place the object in the position you want your character to respawn when checkpoint is reached. There should be some feedback to the player if checkpoint is activated. This can be done with various options such like sound, animation or text.

Create label with NGUI. Write in the text field checkpoint and place the label where you want it to show. The deactivate the label by taking of the checkmark  in the inspector next to the object name. You will activate the label only when checkpoint is reached for the first time.


Create a 2D box collider for the checkpoint object and mark it as trigger. Then create FSM with three states. If you don't want player to get any feedback from the checkpoint then use two states but I'd recommend the three states way. You'll also need one global int variable.


In the first state use action trigger 2D event. Select player as collide tag and create transition event for the action.  The second state needs three actions. First is going to set int value. The variable will be your checkpoint in variable and in the value section you'll need to write 1. 


Second action is going to activate the checkpoint label with activate game object action. Choose your label as the specified game object inside the action.  Last action is wait so that the checkpoint text is shown on the screen long enough for player to read it.


In the last state you're simply going to use the activate game object action again and this time remove the checkmark from activate section.


Then you'll need to update the deathzone FSM. Add state in between the wait and reset player position states. For that state create two events: checkpoint and no checkpoint. Use these as transition events in that state. Create int switch action. In the int variable section choose your checkpoint in variable and make the number of switches 2. First int compare will be 0 and the send event no checkpoint. The second one will be 1 and checkpoint as the send event. This action will compare if the player has reached the checkpoint and will send event to the right state.




Create yet another state for resetting the player position. This time set the X value for position the same as in the checkpoint object. Remember to specify game object and use your character game object for it.

Ei kommentteja:

Lähetä kommentti