var respawnPrefab : GameObject;
function OnTriggerEnter(myTrigger: Collider){
if(myTrigger.gameObject.name == "tum1-2"){//tum1-2 is a wall
//respawns at the location of a game object tagged Respawn in the middle of the game.
var respawns = GameObject.FindGameObjectsWithTag ("Respawn");
for (var respawn in respawns) {
Instantiate(respawnPrefab,
respawn.transform.position, respawn.transform.rotation);
}
Time.timeScale = 1;
}
}
This is my respawn script and it works well. When my collider gameObject hits the wall the player dies and then respawns back at the begining of the level. If the player crashes and dies again using the instantiated cloned gameObject
, a new cloned object appears in my hierarchy called “FPS(clone)(clone)”. The first one was called “FPS(clone)”.
I’m trying to write a script with the expression == null
and !=null
but I can’t figure it out. I’m trying to figure out how to only have one instance of the cloned gameObject
at anyone time. Can anyone help me with this?
I’ve read through many of the answers but I haven’t been able to apply it to my script which is straight out of the Unity API reference under respawn.
How do I destroy the previous cloned game object after respawning again and again? Can someone help me modify my script?
Thanks.