Reputation:
Evening guys, I have a question of why I can't instantiate prefab inside prefab?
ObsSpawner Script:
public GameObject[] Spawner;
// Start is called before the first frame update
void Start()
{
Spawner = GameObject.FindGameObjectsWithTag("SpawnObj");
}
// Update is called once per frame
void Update()
{
foreach (GameObject spawn in Spawner)
{
spawn.SetActive(true);
}
}
but if I put the spawner caller outside prefab that will instantiate those obstacles, is it anything wrong with my script?
Upvotes: 1
Views: 96
Reputation: 20269
You already have references to the prefabs. Just iterate through and Instantiate
them:
public GameObject[] Spawner;
// Start is called before the first frame update
void Start()
{
foreach (GameObject spawn in Spawner)
{
Instantiate(spawn);
}
}
Upvotes: 1