Вылезла ошибка IndexOutOfRangeException: Index was outside the bounds of the array. Spawn.Update () (at Assets/Scripts/Spawn.cs:38)
именно в самом юнити, а не в Visual Studio. Как решить?
Вот код:
public class Spawn : MonoBehaviour
{
public GameObject [] Spawner;
public Transform[] spawnTree;
private int randX;
private int randY;
private int rand;
private int randPosition;
private float spawnRate = 120f;
float nextSpawn;
void Start()
{
}
void Update()
{
if (Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
rand = Random.Range(0, Spawner.Length);
randPosition = Random.Range(0, spawnTree.Length);
Instantiate(Spawner[rand], spawnTree[randPosition].transform.position, Quaternion.identity);
}
}
}