InvokeRepeating affecting parts of script

Hey guys, I need some help,

I have a random enemy wave generator set up and although “InvokeRepeating” works for the swarm ships and circle ships, for some bizarre reason it doesn’t work for the wave ships and the waveTimer stops after one second when the Circle function is launched.

Here is the code

#pragma strict

public var spawners : Transform[];
public var asteroid : Transform;
public var swarmShip : Transform;
public var waveShip : Transform;
public var waveShipR : Transform;
public var selection : int;
public var waveTimer : float;
public var countdown = false;
public var Timer : int;

function Start () 

{
	InvokeRepeating ("Generator", 40.0f, 40.0f);
	yield WaitForSeconds (10);
	audio.Play();
	InvokeRepeating ("Asteroid", 0.01f, 0.5f);
	yield WaitForSeconds (20);
	CancelInvoke("Asteroid");
	
}

function Update()

{
	Timer = Time.time;
	if ((selection == 0) || (selection == 1) || (selection == 2) && (waveTimer <= 30) && (countdown == false))
	{
		waveTimer -= Time.deltaTime;
		countdown = true;
		
		if (waveTimer <= 0.0)
		{
			countdown = false;
			waveTimer = 30.0;
			selection = -1;
		}
	}
	Debug.Log ("Wave Time - " + waveTimer);
}

function Generator()

{
	selection = -1;
	
	if (selection == -1)
	{
		selection = Random.Range(0, spawners.length);
	}
	
	if (selection == 0)
	{
		audio.Play();
		InvokeRepeating ("Swarm", 0.5f, 0.5f);
		if (waveTimer <= 0.0)
		{
			CancelInvoke ("Swarm");
			selection = -1;
		}
	}
	
	if (selection == 1)
	{
		audio.Play();
		Wave();
		WaveR();
		
		if (waveTimer <= 0.0)
		{
			selection = -1;
		}
	}
	

if (selection == 2)
    	{
    		audio.Play();
    		InvokeRepeating ("Circle", 5.0f, 5.0f);
    		if (waveTimer <= 0.0)
    		{
    			CancelInvoke ("Circle");
    			selection = -1;
    		}
    	}
}

function Asteroid ()

{
	var vec = Vector3 (transform.position.x, Random.Range (-3.5f, 5.4f));
	Instantiate(asteroid, vec, transform.rotation);
}

function Swarm () 

{
	var vec = Vector3 (transform.position.x, Random.Range (-3.5f, 5.4f));
	Instantiate(swarmShip, vec, transform.rotation);
}

function Wave ()

{
	for (var i : int = 0; i < 5; i++)
	{
		Instantiate(waveShip, spawners[1].position, spawners[1].rotation);
		yield WaitForSeconds (0.4);
	}
}

function WaveR ()

{
	for (var j : int = 0; j < 5; j++)
	{
		Instantiate(waveShipR, spawners[1].position, spawners[1].rotation);
		yield WaitForSeconds (0.4);
	}
}

function Circle () 

{
	var vec = Vector3 (transform.position.x, Random.Range (-3.5f, 5.4f));
	Instantiate(spawners[2], vec, transform.rotation);
}

These are the sections causing problems.

if (selection == 1)
    	{
    		audio.Play();
    		Wave();
    		WaveR();
    		
    		if (waveTimer <= 0.0)
    		{
    			selection = -1;
    		}
    	}
if (selection == 2)
    	{
    		audio.Play();
    		InvokeRepeating ("Circle", 5.0f, 5.0f);
    		if (waveTimer <= 0.0)
    		{
    			CancelInvoke ("Circle");
    			selection = -1;
    		}
    	}

In the inspector, the selection number shows “1” and the waveTimer starts counting down, however, nothing appears when I try “InvokeRepeating (“Wave”, 3.0f, 3.0f)” and “InvokeRepeating (“WaveR”, 3.0f, 3.0f)”. When they are set as above with just Wave() and WaveR() it works, but only instantiates one set of them and that’s it.

With Circle function, the waveTimer starts and then just stops after one second, the other waves spawn fine, it just means that the circle wave keeps spawning.

And if I try to use “yield WaitForSeconds”, it seems to break the Generator function.

Any ideas?

Any other ideas of how to repeat a function?

Thanks

You can’t use coroutines with InvokeRepeating.