How can I set up a series of OnGUI Toggle buttons in a for loop?

I loop through all the children components inside a GO.

go = GameObject.Find(;
comps = go.GetComponentsInChildren(Transform);

for (var  comp : Transform in comps) {


What i want to do is to create a GUI.Toggle for each GO's children inside the loop.

Is that possible?

Thank you in advance.

Unless the children of the gameobject can change during runtime, I'd recommend getting and storing the list of children in Start(), then looping through the array in your OnGUI method.

var target : Transform;
private var children : Component[];
private var toggles : boolean[];

function Start() {
    children = target.GetComponentsInChildren(Transform);
    toggles = new boolean[children.Length];

function OnGUI() {
    for (var n=0; n<children.Length; ++n) {
        toggleRect = Rect(0,n*20,100,20);
        toggles[n] = GUI.Toggle(toggleRect , toggles[n], children[n].name);  

(excuse the hard-coded rect values there - you'll probably want to modify those!)