Hi I’m trying to add lives to my game I have a static variable of lives which is changed when an my player (ball) object collides with my death zone
levelControls.js attached to a game object:
static var lives = 3;
function restart() {
if(levelControls.lives == 0)
Application.LoadLevel("gameOver");
}
Code on player (ballmove.js):
var force = 20;
var spawnPoint : Transform;
rigidbody.AddForce (0, 0, force);
function Spawn () {
// reset the ball's position to the spawnPoint
transform.position = spawnPoint.position;
levelControls.lives -= 1;
}
function OnDeath () {
Spawn ();
}
When the variable lives reaches 0 it doesn’t load my game over screen. I know the variable is counting down because I have a GUI showing the variable
GUI code (Game HUD.js):
function OnGUI () {
GUI.Label (Rect (25, 160, 100, 30), levelControls.lives.ToString());
}
I’m not very good with code I’m only just learning if anyone could point out what I’m doing wrong that would be a great help!