Hey
I have seen this problem in many other cases, but I haven’t been able to use those fixes on my problem. I get IndexOutOfRangeExeption: Array index is out of range and it points to line 44. The
Instantiate(challanges [Random.Range(0, challanges.Length)], challengesSpawnPoint.position, Quaternion.identity);
public float scrollSpeed = 5.0f;
public GameObject[] challanges;
public float frequency = 0.5f;
float counter = 0.0f;
public Transform challengesSpawnPoint;
// Use this for initialization
void Start () {
GenerateRandomChallange ();
}
// Update is called once per frame
void Update () {
//GenerateObjects
if (counter <= 0.0f) {
GenerateRandomChallange ();
} else {
counter -= Time.deltaTime * frequency;
}
//Scrooling
GameObject currentChild;
for (int i = 0; i < transform.childCount; i++) {
currentChild = transform.GetChild (i).gameObject;
ScrollChallange(currentChild);
if (currentChild.transform.position.x <= -15.0f) {
Destroy (currentChild);
}
}
}
void ScrollChallange (GameObject currentChallange){
currentChallange.transform.position -= Vector3.right * (scrollSpeed * Time.deltaTime);
}
void GenerateRandomChallange(){
Instantiate(challanges [Random.Range(0, challanges.Length)], challengesSpawnPoint.position, Quaternion.identity);
counter = 1.0f;
}
}
I’m watching a tutorial where he changes the size from 0 to 1 and Gameobjects into the “challenges”, but when i try to change it from 0 to 1. It just changes itself back to 0. Does anybody know how to fix this? Thanks in advance!