Help with my variables

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!

I don’t quite see Restart() being called anywhere.

I don’t get what you mean by restart()?

We see that you have a function restart() that loads the gameOver level but that function needs to be called somewhere - it won’t run by itself.

So you either forgot to call it or we need to see that code to help you further.

I get it now! I’ve move my load game over code to my Player (Ball move) code and called the function in my OnDeath function as so!

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 ();
	restart();
}

function OnCollisionEnter (collision : Collision) {
			levelControls.score += 100;   
}

function restart () {
if(levelControls.lives == 0)
		Application.LoadLevel("gameOver");
}

this loads my game over screen! Which is good cause i’ve been banging my head for a while now!

Thanks alot!