Calling a static variable (not working)

Hey, I’m having a little problem but I believe I have some of it figured out, I just need the expertise of you guys :slight_smile: Ok, here’s the problem. I am trying to make a new scene load when a variable in a different script hits a specific value. When the variable hits 0 I want the end game screen to load. The problem is this:

I set the if statement to load the level if the variable = 3 (it is 3 on start up) the end game screen loads fine. But if I change the value to lets say… 0, when the variable hits 0 (when I have destroyed all of my chickens) nothing happens. It is like it’s not updating, can anyone point me in the right direction? Thank you :slight_smile:

The Code:

Collison script which I am trying to reference (name: CollisionChicken.js)

var collisionchicken : GameObject;
static var chickenHit : int = 3;
var explosion : Transform;
var Bwuk : AudioClip;
var myStyle : GUIStyle;

function OnTriggerEnter(c:Collider)
	{
		if(c.gameObject.tag =="bulletShot") 
	
	{
		audio.PlayOneShot(Bwuk);
			chickenHit--;
				Destroy (collisionchicken);
				Destroy (collider);
		 var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
		}
	}

function OnGUI()
	{
    	GUI.Label(Rect(251, 40, 100, 20), ""+ chickenHit.ToString("f0"), myStyle);
	}  

The countdown script (when the variable = 0 I want the end game level to load. Name :Countdown.js)

var myTimer : float;
var myStyle : GUIStyle;

function Awake(){
	DontDestroyOnLoad(gameObject);
}

function Start()
{
myTimer = 0;

}

function Update () {
 if(myTimer > -1){
  myTimer += Time.deltaTime;
 }
}
if (CollisionChicken.chickenHit==3){
	Application.LoadLevel(2);
}

function OnGUI(){
 GUI.Label( Rect(250, 10, 100, 20), ""+ myTimer.ToString("f0"), myStyle );

}

If you need any more information just ask, I will be here for a while :slight_smile:

Your if statement is outside the update. It is not run.

function Update () {
  if(myTimer > -1){
    myTimer += Time.deltaTime;
   }
  if (CollisionChicken.chickenHit<=0){
    Application.LoadLevel(2);
  }
}

Also, I would use <= instead of ==. I do not know how the game looks but if for any reason you would kill two chickens at the same time, then it will drop to -1 and you never load the next level.