Multiple Iteration Schemes

Displayed are 2 Categories each with 5 slots. I am able to Click slots and change there color in this fassion:

1st Slot <--Click and it changes from black (initial state) to white
2nd Slot <--Click and the above changes back to black, and this one changes white
3rd Slot
//...


It happens correctly for when I just display 1-5 slots for one category. But if I need to display two categories, each with 5 slots, something goes wrong:

1st Slot <--Click and changes from black to white
2nd Slot
3rd Slot

//.... GUILayout.Space(15) give us this space between slot categories

1st Slot <-- Changes from black to white w/o being clicked!
2nd Slot
3rd Slot

so on and so forth, in that way..thus the weiredness is revealed..I don't know how to fix it!! Please help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

        void OnGUI() // Method similar to Update, its for all the GUI fuss.
        {
           DisplaySlots();
        }

        void DisplaySlots()
	{	
	   GUILayout.BeginArea(new Rect((Screen.width/1.5f)+45, (Screen.height)/2-60, 180, 500));
		
	   for (int i = 0; i < 2; i++) // Give the number of SlotCategories to contain 5 slots
	   {
		  for (int j = 0; j < 5; j++) // Give the number of actual Slots (5)
		  {
			  if (GUILayout.Button(Slots[i][j], SlotCategory[i][j])) // Display Slots
			  {
			        // If we clicked an individual slot, we are here!	 	
				  for (int slot = 0; slot < 5; slot++)
				  {
					  if (slot == j) // which slot did we click?
					  {
					        SlotCategory[i][j].normal.textColor = Color.white;
					  }
					  else
					  {
					        SlotCategory[i][slot].normal.textColor = Color.black;
					  }
				  }
					
			  }
		  }
		  GUILayout.Space(15);
	       
	  }
	        GUILayout.EndArea();
        }



The only thing that I keep telling myself is "keep in <i>this</i> 'i'! I coded this completely myself and just cannot seem to figure it out from here! <CRIES>
Last edited on
Efficiency is my concern here. I broke everything up so it is easier to read:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    void DisplaySlots()
	{	
		GUILayout.BeginArea(new Rect((Screen.width/1.5f)+45, (Screen.height)/2-60, 180, 500));
		
		if (GUILayout.Button(SlotCategory[0][0], Slots[0]))
		{
			for (int slot = 0; slot < 5; slot++)
			{
				if (slot == 0) Slots[0].normal.textColor = Color.white;
				else Slots[slot].normal.textColor = Color.black;
			}
		}
		
		if (GUILayout.Button(SlotCategory[0][1], Slots[1]))
		{
			for (int slot = 0; slot < 5; slot++)
			{
				if (slot == 1) Slots[1].normal.textColor = Color.white;
				else Slots[slot].normal.textColor = Color.black;
			}
		}
		
		if (GUILayout.Button(SlotCategory[0][2], Slots[2]))
		{
			for (int slot = 0; slot < 5; slot++)
			{
				if (slot == 2) Slots[2].normal.textColor = Color.white;
				else Slots[slot].normal.textColor = Color.black;
			}
		}
		
		if (GUILayout.Button(SlotCategory[0][3], Slots[3]))
		{
			for (int slot = 0; slot < 5; slot++)
			{
				if (slot == 3) Slots[3].normal.textColor = Color.white;
				else Slots[slot].normal.textColor = Color.black;
			}
		}
		
		if (GUILayout.Button(SlotCategory[0][4], Slots[4]))
		{
			for (int slot = 0; slot < 5; slot++)
			{
				if (slot == 4) Slots[4].normal.textColor = Color.white;
				else Slots[slot].normal.textColor = Color.black;
			}
		}
		
		GUILayout.EndArea();
	}


The above works just as it should! I just don't want to copy and paste then change indices for however many times I need the text to be displayed...If someone needs more clarification I would be happy to provide that..
Last edited on
Topic archived. No new replies allowed.