- Home /
Question by
bzerk122 · Jan 06, 2013 at 03:47 AM ·
c#errorarrayargumentoutofrangeexception
Getting ArgumentOutOfRangeException on array c#
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerInv : MonoBehaviour {
//(CHANGE)
//Gun AMMO (NOT FINAL PLEASE CHANGE TO MORE SPECIFIC NAMES TO CERTAIN GUN TYPES)
public int AssaultA;
public int SmgA;
public int PistolA;
public Vector2 scrollPosition;
public List<string> Items;
public Texture BackPack;
public Texture gun;
public int ArrayCounter;
void Update(){
}
void OnGUI(){
Rect rect = new Rect(0,0,800,600);
GUI.DrawTexture(rect,BackPack);
GUILayout.BeginArea(new Rect(40,100,200,400));
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(200), GUILayout.Height(500));
foreach(string go in Items){
GUILayout.Button(Items[ArrayCounter]);
ArrayCounter++;
}
GUILayout.EndScrollView();
GUILayout.EndArea ();
}
}
I keep getting this error
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.String].get_Item (Int32 index) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections.Generic/List.cs:633)
PlayerInv.OnGUI () (at Assets/Scipts/PlayerInv.cs:33)
Comment
Best Answer
Answer by RazorCut · Jan 06, 2013 at 03:50 AM
Before the foreach loop in the OnGUI function set ArrayCounter to 0.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
how can i check if index exists? 2 Answers
NullReferenceException problem 2 Answers
"Strange behaviour may occur" when using Network.AllocateViewID() 0 Answers
IndexOutOfRangeException help on debug 3 Answers