Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

How do i use foreach/for loops properly?

$
0
0
Hello, I'm currently starting to expand my skills in the gui side of scripting, I've seen that foreach/for loops can be used to give each i in a list the same property or do something * the amount of things in the list, but how do i use it properly? the script at the bottom of this thread currently loops forever, do i have to move it to its own function or perhaps add a bool? so it only loops when the bool is true? any help would be greatly appreciated, thanks! the script Delcaring public Rect slotRect; public Rect slotRectoffset; public List TestList= new List(); void start TestList.Add("0"); TestList.Add("1"); void OnGUI() foreach(string i in TestList) { GUI.Button (new Rect (slotRect.x + slotRectoffset.x, slotRect.y + slotRectoffset.y, slotRect.width, slotRect.height), i); slotRectoffset.x += 50; }

Viewing all articles
Browse latest Browse all 184

Trending Articles