I want to spawn 3 of the same game object at a random spawn point that I put into a list. But everytime I run my project there’s an error saying ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
I was wandering how does this error is happening, or there can be a better way to do what i am trying to implement?
private void Start()
{
foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Savee"))
{
saveePoints.Add(obj);
}
spawn();
}
void spawn()
{
for (int i = 0; i <= 2; i++)
{
i = Random.Range(0, saveePoints.Count);
saveePoints _= Instantiate(saveeObject, saveePoints*.transform.position, transform.rotation) as GameObject;*_
}
}