- Home /
Array out of Index,array out of index
I am creating Ball Panic Game and when I am shoot the arrow it show error and I can't figure it out this........please help!!
""public void ShootTheArrow() {
if (Input.GetMouseButtonDown (0)) {
if (shootOnce) {
shootOnce = false;
StartCoroutine (PlayerTheShootAnimation ());
Instantiate(arrows[0], new Vector3 (transform.position.x, height, 0), Quaternion.identity);
} else if (shootTwice) {
shootTwice = false;
StartCoroutine (PlayerTheShootAnimation ());
Instantiate (arrows [1], new Vector3 (transform.position.x, height, 0), Quaternion.identity);
}
}
}"",System.IndexOutOfRangeException: Array index is out of range.
at PlayerScript.ShootTheArrow () I am working on a Ball Panic game and I can't figure it out this error...trying to shoot the arrow. please help !!
Answer by wizbit · Nov 01, 2018 at 03:38 PM
Hey @khannaharsh774,
This error normally indicates that the code is attempting to collect data from an array but the array is either "empty" or not initialized, or your attempting to collect data from a position that is higher the index count of the array.
Use "Debug.Log" to output your array.count or the data assigned to "arrows". because i suspect that the array will be empty or NULL.
Check that the array is getting populated, and if you need to specify the selection of prefabs in the inspector, do that.
Your answer
Follow this Question
Related Questions
Mesh.colors is out of bounds 0 Answers
Find if no objects with tag exist 3 Answers
I'm getting an index out of range error even though my arrays are filled with elements? 2 Answers
Resizable Array of Classes? 2 Answers
Class Array referencing 1 Answer