Hi all,
i found some similar topics but i can not find exact solution for my problem.
I have got set an array of 4 spawn positions but when the spawn rate is high it results that sometimes objects are spawning at the same position so it is not good for my game as they stack and i need to exclude from the array that spawn position where is still a game object so they do not stack. See my code below.
If you can help and write a code so i can see exactly what to do it will be great.
(Note: I have more methods included in StartGame() so i need to use the coroutine)
public GameObject egg;
public Transform[ ] spawnEggPos;
private float spawnRate = 1.0f;
IEnumerator SpawnEggs()
{
yield return new WaitForSeconds(spawnRate);
int spawnPosIndex = Random.Range(0, spawnEggPos.Length);
Instantiate(egg, spawnEggPos[spawnPosIndex].position, Quaternion.identity);
}
public void StartGame()
{
StartCoroutine(SpawnEggs());
}