7.5 – Coroutine events

Since you can use yields in javascript without any modification, this example will only cover C#.

Create a scene with a panel and a button, with variableName panel1 and button1. We’ll align panel1 to the left of the screen when button1 is clicked.

public void button1_Click(iGUIButton caller){
    panel1.setX(0);
}

But what if you want to align it after 2 seconds. You have to use coroutines (yield) . To use coroutines in iGUI events, just change the return type of event method from void to IEnumerator. iGUI will automatically sense and treat the method as a coroutine.

public IEnumerator button1_Click(iGUIButton caller){
    yield return new WaitForSeconds(2);
    panel1.setX(0);
}