Hello I have been working to try and figure this out for about 7 hours now(because I don’t have to programming experience) and can’t seem to get it.
My setup up is I have a gameobject that contains a pool of different objects(not active) that gets instantiated at run. I need to somehow find every object in the pool and randomly activate them at different times. Then move them to different spawn areas so they can do what they need to(i.e. move across the screen(I am working in 2D)). This is my script I have been messing with:
using UnityEngine;
using System.Collections;
public class SpawnPoolItems : MonoBehaviour {
public Transform[] spawnPoints = new Transform[6];
public float spawnMin = 1.0f;
public float spawnMax = 2.0f;
private GameObject[] prefabsToActivate;
private GameObject[] items;
private int randomActive;
// Use this for initialization
void Start ()
{
Spawn();
}
void Spawn()
{
foreach(Transform child in this.transform)
{
child.gameObject.SetActive(true);
/*for(int i = 0; i < items.Length; i++)
{
}
*/
}
//Invoke("Spawn", Random.Range(SpawnMin, SpawnMax));
}
}
I’ve tried multiple things with for and foreach loops but I keep getting errors and end up back at square one(which is where this script above sits). If anyone has any suggestions on how to do this please help I would be very grateful.