- Home /
Push down GUI everytime for loop cycles through Array
Im trying to display a GUI box every time i cycle through a for function. And every time it does add a little bit to the height variable for that gui box so it goes under the previous one. Here is what i have:
for (i = 0; i < indivSpotNo.Length; i++) {
hgt += 30f;
GUI.Box (new Rect (20, hgt, 30, 25), indivSpotNo [i].ToString());
}
}
except what is happening is the hgt variable isnt stopping for each one its just adding every time and pushing them all off screen. What else can i do that will achieve this?
Answer by RudyTheDev · Dec 04, 2014 at 11:26 AM
I assume hgt
is declared outside the method and you don't reset it?
hgt = 0;
for (i = 0; i < indivSpotNo.Length; i++)
{
hgt += 30f;
GUI.Box (new Rect (20, hgt, 30, 25), indivSpotNo [i].ToString());
}
thanks. that worked. I did declare it in the start function as 0. I dont see how its any different. But it worked.
Start
only happens once, but (I assume yours is) OnGUI
every time UI is redrawn. hgt
does not get reset back to 0 between one OnGUI
call and the next.
Your answer
Follow this Question
Related Questions
How to save a 2d-array in C# 2 Answers
How to select an Game Object from an Item List 0 Answers
One variable set TRUE when another must be false. TOGGLE 3 Answers
How to make a or array of GUI.Button's? 1 Answer
images assigned to gameobjects by tag 2 Answers