If statement not working

Hello, I’m having trouble getting my if statements to start.

if(Wave1 > 0)
	{
		Debug.Log("Check");
	}

Here I want it when Wave1 is set to the value of 1, it will Debug.Log(“Check”);

function OnTriggerEnter ()
{
		SurvivalScript.Wave1 += 1;
}

This is a different script which will add 1 to the Wave1 value.

I want it so it adds 1 to the value when you enter the trigger, then logs (“Check”). Wave1 is a static int and I’m getting no scripting errors, yet I’m getting nothing in the console.

Please help me,
Thanks.

Your if statement is in a function called Survival, which is called from the Start method. In Unity, the Start method is only called once when the game object is constructed. I think that your OnTriggerEnter method is being called AFTER the SurvivalScript’s Start method has been called, so the if statement never has a chance to respond to the wave increasing

I think what you’re trying to do is to poll the state every frame. Try updating your SurvivalScript to this:

 static var Wave1 : int = 0;
 
 function Update()
 {
     Survival();
 }
 
 function Survival ()
 {
     if(Wave1 > 0)
     {
         Debug.Log("Check");
     }
}

Just be aware that the Update method will be called every frame, so you will get a lot of Debug.Log statements printing.

Good luck friend!

Check if the OnTriggerEnter function actually gets called