SetActiveRecursively (seriously need some help)

Hello,

I seriously need some help with this:

I have a trigger set up when my player (myrobot) enters it, it will then make the objects in that room active.

Trigger Code:

var activeObjects : GameObject;

function Start()
{
	activeObjects.SetActiveRecursively(false);
}

function OnTriggerEnter(other : Collider) 
{
	if(other.gameObject.tag == "myrobot")
	{
		activeObjects.SetActiveRecursively(true);
	}
}
function OnTriggerExit(other : Collider) 
{
	if(other.gameObject.tag == "myrobot")
	{
		activeObjects.SetActiveRecursively(false);
	}
}

It works great! with everything I’ve used so far Except when I create a wave, so I figured out other ways to avoid the wave (below) until now and I need some help sorting this out.

Wave:

var spawnPoints : Transform[];  // Array of spawn points to be used.
var enemyPrefabs : GameObject[]; // Array of different Enemies that are used.
var amountEnemies = 20;  // Total number of enemies to spawn.
var yieldTimeMin = 2;  // Minimum amount of time before spawning enemies randomly.
var yieldTimeMax = 5;  // Don't exceed this amount of time between spawning enemies randomly.
var effect : GameObject;//particle effect

function Start()
{
    Spawn();
}

function Spawn()
{ 
   for (i=0; i<amountEnemies; i++)// How many enemies to instantiate total   
   { 
      // How long to wait before another enemy is instantiated.      
      yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax)); 
      
      // Randomize the different enemies to instantiate.       
	  var obj : GameObject = enemyPrefabs[Random.Range(0, enemyPrefabs.length)];
	  
	  // Randomize the spawnPoints to instantiate enemy at next.
	  var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];
	    
	  Instantiate(obj, pos.position, pos.rotation);//instantiate enemies
	  Instantiate(effect, pos.position, pos.rotation);//instantiate effect
	   
   } 
}

The only thing I can think of is that the wave wont work with a for loop statement?

When my player enters the trigger it is working because the object goes from “not active” to active so it is working the code in the wave is just not playing out for some reason and Im stumped?

If I take the wave out of the SetActiveRecursively gameObect it works fine.

Sooo I just dont know what to do? Im going to try and create a for statement loop that will print text to the screen and see if that works using the trigger. I dont know how to write the code for that yet but I gotta try something Ive tried everything else I can think of.

If anyone Knows a Solution or WorkAround please enlighten me :slight_smile:

Solved I did away with the SetActiveRecursively and just created a regular trigger for the waves :slight_smile: