checkpoint question????

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

thanks in advance

On your player add a public variable

public Collider currentCheckPoint;

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.

void OnTriggerEnter() {

   PlayerScript myPlayer = (PlayerScript) GameObject.Find("Playerobject").GetComponent("PlayerScript");

   myPlayer.currentCheckPoint = this;

}

Now you can find out where the check point is when he dies and move the player.

Inside the player's script you can have a function like this:

void PlayerDied() {

  this.transform.position = currentCheckPoint.position;

}

http://unity3d.com/support/resources/tutorials/3d-platform-game

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.

Javascript? Try this.

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);
    }
}
}

Hopefully this works.

I explain how to create a checkpints system in my blog: https://santiandrade.github.io/Unity-Creating-a-checkpoints-system/

Good luck!

A Video Is Made By Me On Same Topic!
Link Of Video Is How To Make A Ball Game In Unity-Part7 - YouTube

You Should Also Search For Saving Scene By Script This Might Also Help You!
I Am Working On It.