- Home /
Need help with a checkpoint system
Hello. I was trying to make a checkpoint system. I wrote a script that should save your respawn place when you die.
private var dead = false;
function OnCollisionEnter(hit : Collision) { if(hit.gameObject.tag == "Terr") { dead = true; print ("NOOO!"); HealthControl.LIVES -= 1; }
if(hit.gameObject.tag == "checkpoint") { gameObject.Find("Respawn").transform.position = transform.position; Destroy(hit.gameObject); } }
function LateUpdate() { if(dead) { gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10); transform.position = gameObject.Find("Respawn").transform.position; dead = false; } }
I dont understand what could be wrong to the script, but when I collide with my terrain I lose my main character and when I collide with my checkpoint and then with the terrain I get an error saying "null reference exeption". Whats wrong? Thank you for help, I hope you understand what I said.
Your answer
Follow this Question
Related Questions
Checkpoint system??? 3 Answers
simple checkpoint/save/load system in javascript 4 Answers
Accessing local system ( File Browser ) 2 Answers
Checkpoint system in platformer 1 Answer