Hi i make a 2D endlessrunner and now im write the script for an obstacelspawner but an error is still there. here is the code for the spawner
IEnumerator SpawnRandomObstacle()
{
yield return new WaitForSeconds(Random.Range(1.5f, 4.5f));
int index = Random.Range(0, obstaclesToSpawn.Count);
while (true)
{
if (!obstacleToSpawn[index].activeInHierarchy)
{
obstaclesToSpawn[index].SetActive(true);
break;
}
else
{
index = Random.Range(0, obstaclesToSpawn.Count);
}
}
StartCoroutine (SpawnRandomObstacle ());
}