I found a respawn script to make my player die and respawn in the area in first began in. But the problem is that it keeps creating clones everytime the player falls and dies. I need help if anyone can give me a heads up.
var Player:Transform;
var spawn:Transform;
function OnTriggerEnter(col:Collider) {
if(col.tag =="Player"){
//your death script
Instantiate(Player,spawn.position,spawn.rotation);
}
}
Only re- Instantiate() your player if you are actually Destroy()-ing it.
Otherwise simply move it
Pretty much what meat5000 says. If you want to move the character something like this would work.
var spawnLocation : Transform; //can be an empty object
var player : Transform; //the player
function Update()
{
if(health == 0) //this is how the function gets triggered, you can just use an IF. It's up to you how you trigger it.
{
playerSpawn();
}
}
function playerSpawn()
{
player.position = spawnLocation.position; //this is the psawning part. It will set your players position to the spawn objects position.
}