Answer the question
In order to leave comments, you need to log in
Unity error IndexOutOfRangeException: Array index is out of range?
public GameObject[] obj;
private GameObject installed_object;
private int rand=0;
public int spawnTime=50;
private float TimeToDeploy=1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (TimeToDeploy >= 150)
{
rand = Random.Range(0, obj.Length - 1);
installed_object = Instantiate(obj[rand], obj[rand].transform.position, Quaternion.identity) as GameObject;
installed_object.transform.localPosition = new Vector3(0, 3.2f, 36);
TimeToDeploy -= 150;
}
else
TimeToDeploy += Time.deltaTime*spawnTime;
}
installed_object = Instantiate(obj[rand], obj[rand].transform.position, Quaternion.identity) as GameObject;
Answer the question
In order to leave comments, you need to log in
Rave. As it always happens ... I recreated the script already on the cube and not on the GameObject and everything worked. Returned as it was and there are no errors. Works as with (0, obj.Length); So is (0, obj.Length-1);
I don't understand these jokes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question