Code not entering if statement.

I can’t for the life of me figure out why this script won’t enter this if statement. I must be overlooking something so I’m hoping a fresh set of eyes can see if there is something I’m overlooking.

Basically the code works fine and get’s to the statement "under 1 minute, waiting for "+waiftFor. But when the next set of if statment checks happens ( if (getPlayTime >= waitFor ) nothing happens. It goes on until infinity.

for anyone curious “getPlayTime” is a pause variable replacement for Time.time. And yes, it is keeping track of Time.time as it should. everything is working fine, up until this if statement.

I know this is somewhat hard to follow…it’s a work in progress.

#pragma strict

var playerDamage: 				float = 0;				//records the damage the player has taken

var spawnIsActive:				boolean = true;
var waveActive:					boolean = true;			//toggles for controlling the wave
var spawnEnemies: 				boolean = true;			//
var bigSpawn:					boolean = false;
var firstWaveActive:     		boolean = true;
var secondWaveActive: 			boolean = false;

var healthCount: 				int = 10;				//players health count
var resourceCount: 				int = 100;

var waveText: 					UILabel;				//ui label 
var resourceText: 				UILabel;
var waitFor:					float = 0.0;

var waveLevel:					int = 0;				//current wave we are on
var waveLength: 				float = 0;			    //how long does the wave last before it stops
var intermissionTime: 			float = 15.0;			//how long to wait inbetween waves

var enemyPrefabs: 				GameObject[];			//array that contains all the enemy types
var enemyPrefabs02:				GameObject[];				
var alienSpawnPoints: 			Transform[];			//contains the spawn points
var respawnMinBase:				float = 3.0;			//used to ramp up the amount of spawns
var respawnMaxBase: 			float = 10.0;			//
private var respawnMin: 		float = 3.0;			//
private var respawnMax: 		float = 10.0;			//
private var waveEndTime:		float = 0.0;
private var recSpawnActivity:	boolean = false;

var holdSeconds:  				int = 0;
var holdMinutes: 				int = 0;
var holdFirstWave: 				boolean;
var holdSecondWave:				boolean;
var holdBigWave:				boolean;

var difficulty: 				int = 0;
var seconds: 					int = 0;
var minutes:					int = 0;

private var getClock:			GameObject;				// getting clock and all it's components
var getPlayTime: 				float = 0.0;
private var getPlayTimeEnabled: boolean = true;

function Start ()
{
	UpdateHUD ();
}

function Update () 
{	
	getClock = GameObject.FindGameObjectWithTag("clock");
	getPlayTime = getClock.GetComponent(clock).playTime;
	getPlayTimeEnabled = getClock.GetComponent(clock).playTimeEnabled;

	if (getPlayTimeEnabled)
	{
		if ( spawnIsActive )
		{
			Clock ();
			if (waveActive)
			{
				if ( getPlayTime >= waveEndTime )
				{
					spawnEnemies = false;
					FinishWave ();
					print ( "shutting off wave");
				}
			}
			if ( minutes >= 1 && firstWaveActive )
			{
				firstWaveActive = false;
				secondWaveActive = true;
				print ( "swapping over to second wave level");
				waveLength = 5;
			}
			if ( waveLevel == 09 && secondWaveActive )
			{
				secondWaveActive = false;
				bigSpawn = true;
				print ( "swapping over to big spawn");
				waveLength = 40;
				FinishWave ();
			}
			if ( minutes >= 4 )
			{
				difficulty = minutes - 2;
			}
		}
		else 
		{
			recSpawnActivity = true;
		}
	}
}

function RecordSpawnActivity ()
{
	holdSeconds = seconds;
	holdMinutes	= minutes;
	holdFirstWave = firstWaveActive;
	holdSecondWave = secondWaveActive;
	holdBigWave = bigSpawn; 
	
	recSpawnActivity = false;	
}

function FinishWave ()
{
	waveActive 		= false;	
	spawnEnemies 	= false;
	var i: 			float;	
	i 				= Random.Range (20.0, 30.0);
	waitFor 		= getPlayTime + i;
	
	print ("under 1 minute, waiting for "+waitFor);
	
	if ( firstWaveActive && getPlayTime >= waitFor )
	{
		SetNextWave ();													//sets the next wave command
		StartNewWave ();
	}
	if ( secondWaveActive )
	{
		i = Random.Range (12, 18);
		print ("over 1 minute, waiting for "+i);
		yield WaitForSeconds (i);										//waits for the the intermission time to pass
		SetNextWave ();													//sets the next wave command
		StartNewWave ();		
	}
	if ( bigSpawn )
	{
		print ("HERE THEY COME!!!");
		yield WaitForSeconds (10);
		SetNextWave ();
		StartNewWave ();
	}
	
}

function SetNextWave ()												//prepares the values for the next wave (how many enemies will be spawn)
{
	waveLevel ++;  										 			//ups the wave level
}

function StartNewWave ()
{
	UpdateHUD ();													//updates the gui
	NewSpawnEnemy ();												//spawns new enemy
	waveActive = true;												//sets the toggle to spawn enemies
	spawnEnemies = true;
	waveEndTime = getPlayTime + waveLength;
}

function UpdateHUD ()
{
	waveText.text = "Wave: " +waveLevel;							//updates the current waveLevel to the wave GUI
	resourceText.text = "Resources: " +resourceCount;				//updates the current healthLevel to the health GUI
}

function NewSpawnEnemy ()
{
	if ( minutes <= 1 && firstWaveActive && !bigSpawn )
	{
		FirstLevelSpawn ();
		print ("first level spawn happening");
	}
	if ( minutes >= 1 && !bigSpawn && secondWaveActive && !firstWaveActive )
	{
		SecondLevelSpawn ();
		print ("second spawn happening");
	}
	if ( bigSpawn && !secondWaveActive )
	{
		BigSpawn ();
		print ("big spawn happening");
	}
}

function FirstLevelSpawn ()
{
	var i = difficulty;
	for (; i >= 0; i--)
	{
		var enemyChoice = Random.Range (0, enemyPrefabs.Length);
		var spawnChoice : int;	
		spawnChoice = Random.Range (0, alienSpawnPoints.Length);
		Instantiate (enemyPrefabs[enemyChoice], alienSpawnPoints[spawnChoice].position, alienSpawnPoints[spawnChoice].rotation);
		print ( "1 enemy spawned");
	}
}	

function SecondLevelSpawn ()
{	
	var i = difficulty;
	for (; i >= 0; i--)
	{
		var enemyChoice = Random.Range (0, enemyPrefabs02.Length);
		var spawnChoice : int;	
		if ( enemyChoice == 1 )
		{
			var a = 1;
			for (; a >= 0; a--)
			{
				spawnChoice = Random.Range (0, alienSpawnPoints.Length);
				Instantiate (enemyPrefabs02[enemyChoice], alienSpawnPoints[spawnChoice].position, alienSpawnPoints[spawnChoice].rotation);
			}
		}
		if ( enemyChoice == 0 )
		{
			spawnChoice = Random.Range (0, alienSpawnPoints.Length);
			Instantiate (enemyPrefabs02[enemyChoice], alienSpawnPoints[spawnChoice].position, alienSpawnPoints[spawnChoice].rotation);
		}
	}
	print ( "second level spawn finished" );
}

function BigSpawn ()
{
	print ("Big Spawn!");
	var i = 3;
	for (; i >= 0; i--)
	{
		var enemyChoice = Random.Range (0, enemyPrefabs02.Length);
		var spawnChoice : int;	
		if ( enemyChoice == 1 )
		{
			var a = 1;
			for (; a >= 0; a--)
			{
				spawnChoice = Random.Range (0, alienSpawnPoints.Length);
				Instantiate (enemyPrefabs02[enemyChoice], alienSpawnPoints[spawnChoice].position, alienSpawnPoints[spawnChoice].rotation);
			}
		}
		if ( enemyChoice == 0 )
		{
			spawnChoice = Random.Range (0, alienSpawnPoints.Length);
			Instantiate (enemyPrefabs02[enemyChoice], alienSpawnPoints[spawnChoice].position, alienSpawnPoints[spawnChoice].rotation);
		}
		print ( "big spawn loop "+i);
	}
	bigSpawn = false;
	secondWaveActive = true;
	waveLength = 5;
	print ("big spawn finished");
}

function Clock ()
{
	seconds = getPlayTime % 60;
	minutes = getPlayTime / 60;
}

OK nevermind, I solved this. The reason that it never entered the if statement was because at the moment the code goes into the function, the statement isn’t true. Because the function isn’t updating every frame, it will never check to see when that statement will become true. Thus, we get locked in the function.

Hope that makes sense to anyone following my silly little drama…lol. I’m a noob :frowning: