I’m trying to get some strings saved in an arraylist to show up on the GUI,
but for some unkown reason to me, it won’t stop after going through the arraylist and keeps going on for ever.
i’m using the foreach, because i want each entry only to show up once.
there’s nothing wrong with the code itself (i think), but it has something to do with the foreach at the bottom of the code.
Help really appreciated!
Main:
public static string Box1Contents;
public static string Box2Contents;
public static string PlayerContents;
public static ArrayList Box1Array = new ArrayList();
public static ArrayList PlayerArray = new ArrayList();
public static ArrayList Box2Array = new ArrayList();
Start:
void Start () {
Box1Array.Add("one");
Box1Array.Add("two");
Box1Array.Add("three");
PlayerArray.Add("six");
Box2Array.Add("four");
Box2Array.Add("five");
}
OnGUI:
if (GUI.Button(new Rect(460, 400, 140, 65), "Pick Up"))
{
switch (Player.triggeredObject)
{
case "Box1":
if (Box1Array.Count > 0)
{
PlayerArray.Add(Box1Array[Box1Array.Count - 1].ToString());
Box1Array.RemoveAt(Box1Array.Count - 1);
GameManager.Box1Contents = "";
GameManager.PlayerContents = "";
}
break;
case "Box2":
if (Box2Array.Count > 0)
{
PlayerArray.Add(Box2Array[Box2Array.Count - 1].ToString());
Box2Array.RemoveAt(Box2Array.Count - 1);
GameManager.Box2Contents = "";
GameManager.PlayerContents = "";
}
break;
default:
//nothing
break;
Also OnGUI:
foreach (object s in Box1Array)
{
Box1Contents = Box1Contents + s + "
";
}
foreach (object t in PlayerArray)
{
PlayerContents = PlayerContents + t + "
";
}
foreach (object u in Box2Array)
{
Box2Contents = Box2Contents + u + "
";
}