- Home /
Count Deaths
Okay, so basically I am making a 2D Platformer game. I've sat so each time you get out of range of the camera, you die and get spawned back to a certain point X Y Z. Now this script is added to a cube with box collider and "is trigger" checked. I would like to do so a guitext COUNTS how many times they fall down there, but I don't know how to, any ideas? Here's my death fall script, if it is of any help:
var spawnPoint : Transform; var spawnPointX = -0.001256943; var spawnPointY = 2.869796; var spawnPointZ = -2.352078e-08;
function OnTriggerEnter(other : Collider) {
if(other.tag == "Player"){
other.gameObject.transform.position = Vector3(spawnPointX, spawnPointY, spawnPointZ);
}
}
Answer by Kiwasi · May 21, 2014 at 12:26 AM
Basically you create a int and add one every time the player dies. Then you use OnGUI and GUI.Button (look these up in the reference).
Here is the C# version
private int noDeaths;
void OnTriggerEnter(Collider other) {
if(other.tag == "Player"){
other.gameObject.transform.position = new Vector3(spawnPointX, spawnPointY, spawnPointZ);
noDeaths = noDeaths + 1;
}
}
void OnGUI() {
GUI.Label(new rect(20,20,100,100),"Deaths: " + noDeaths.ToString())
}
Answer by kamgru123 · May 20, 2014 at 11:12 PM
Add a reference to the GUIText withing the script and set the text property of GUIText.