- Home /
Question by
JoshMBeyer · Nov 05, 2014 at 09:54 PM ·
arraylengthoutof
Why is this array out of length?
public bool HideAllObjects;
public GameObject[] ObjectsToHide;
void Update()
{
if (HideAllObjects)
{
ObjectsToHide[ObjectsToHide.Length].SetActive(false);
}
Comment
Best Answer
Answer by AlwaysSunny · Nov 05, 2014 at 10:00 PM
The length of an array is the number of elements, but element indexes start with zero.
The last element's index is the array length minus one.
ObjectsToHide[ObjectsToHide.Length-1]
Your answer
Follow this Question
Related Questions
Array out of its own range? 4 Answers
C# - IndexOutOfRangeException - Array index is out of range 2 Answers
Array index is out of Range!? 1 Answer
Wierd Animation Bug 0 Answers
Unity Array.Length Bug/Problem? 1 Answer