Hello! I have a problem with part of my programm. I was trying to save instances of a GameObject into an array for later which worked just fine. Now i wanted to iterate though the array with a “for” loop. Going from slot 0 to slot array.length.
.
For some reason this gives me an error message which is this one:
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
1
System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/ArrayList.cs:3261)
System.Collections.ArrayList.get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/ArrayList.cs:2652)
UnityScript.Lang.Array.get_Item (Int32 index)
ButtonFucntions.SaveValues () (at Assets/Scripts/ButtonFucntions.js:177)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:154)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
.
My Code:
for(var i : int = 0; i <= eventsArray.length; i++){
DayDisplayInstance = eventsArray*;*
-
child = DayDisplayInstance.transform.GetChild(0).gameObject;*
-
myText = child.GetComponent.<Text>();*
-
print(myText.text);*
-
}*
I don’t know if this is the easiest solution to get the Text component of a child of my Object but it works.
Any ideas what my problem could be? It should be pretty simple I guess, I have just never really worked with arrays in Unity.
.
Thanks a lot in advance!!!
(if you need more parts of the code feel free to ask)