how can i make chekpoint system in unity. like when player touch 1st check point collider then die so he re spawn at 1st check point position if the the player touch 2nd check point & then die so, he re spawn at 2nd check point position
so, basically how to store these information in the script
Then create empty game objects with a box collider set to "Trigger" and create a script like this, make sure you replace "PlayerScript" with the name of your player's main control script and "Playerobject" with the name of your players gameobject.
This tutorial has exactly what you need, a set of check points that are activated and deactivated as you walk over them. Just read the tutorial and lift the code from the resources.
private var originalSpawn : boolean = true;
private var respawn2 : boolean;
private var respawn1 : boolean;
function OnTriggerEnter(other : Collider)
{
//You'll have to make a death script and make a boolean true false command.
if (dead == true)
{
if (originalSpawn == true)
{
//Put your coordinates of the original spawn point.
transform.position = Vector3(x, y, z);
}
}
if (other.gameObject.tag == "Checkpoint1")
{
originalSpawn = false;
respawn1 = true;
respawn2 = false;
}
if (respawn1 == true)
{
if (dead == true)
{
//Put your coordinates of the spawn point.
transform.position = Vector3(x, y, z);
}
}
if (other.gameObject.tag == "Checkpoint2")
{
originalSpawn = false;
respawn2 = true;
respawn1 = false;
}
if (respawn2 == true)
{
if (dead == true)
{
//Put your coordinates of the spawn point.
transform.position = Vector3(x, y, z);
}
}
}