non-displaying GUILayout elements when using yield WaitForSeconds()

Hi,

I am trying to update the content of a GUILayout.Box every second. For doing the job I thought about using yield WaitForSeconds(1) and a boolean in the OnGUI(), as shown below. The problem is that it does not show the GUILayout.Box. I checked (through print()) that the function is called every second (so the WaitForSeconds(1) works perfectly) and prints (through the print()) the values I want.

So, I don't know why the GUI.Layout is not displayed...

I would apreciate very much any help

function OnGUI () {

    if (!auxbool){ 

        functionName(index);        
    }

function funtionName (num : int) {

    GUILayout.BeginArea(Rect(800,10,80,200));
    // Starts a vertical group
    GUILayout.BeginVertical ("box");
    GUILayout.Box (Resources.Load("image"),GUILayout.ExpandWidth(false) );

    GUILayout.Box ( ""+aux[num],foGuiStyle);

    GUILayout.EndVertical();
    GUILayout.EndArea();    

    auxbool = true;
    yield WaitForSeconds(1);
    auxbool = false;
}

Unity's GUI system (OnGUI + GUI.* + GUILayout.* etc) work in immediate mode - you have to call your gui items every frame you want them on the screen

Right now you're only drawing them once every second, which has the effect of looking like it's not drawing them at all

I can't see why you're doing it in this instance, but if you need to do heavy calculations, do that part alone once a second, leave the gui rendering as it is

To change your value once a second:

var str = "Test";
var strToShow = "";

function Start()
{
    InvokeRepeating("UpdateValue", 1, 1);
}

function UpdateValue()
{
    strToShow = str;
}

So, the solution is solved in a previous thread. Though I read it before I thought my case was different, but not.