index was outside the bounds of the array cs:33
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ComodScript : MonoBehaviour { public GameObject[] Comods; int index; void Start() { index = 0; } void Update() { if(index > 3) index = 0; if(index==0) { Comods[0].gameObject.SetActive(true); } } public void ButtonNext() { index += 1; for(int i = 0; i < 4; i++) { Comods[i].gameObject.SetActive(false); Comods[index].gameObject.SetActive(true); } } }
0
(N - 1)
Quote: public void ButtonNext() { index += 1; //<- here index might become 4 for(int i = 0; i < 4; i++) { Comods[i].gameObject.SetActive(false); Comods[index].gameObject.SetActive(true);//<- here index = 4 is a problem } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)