OnGUI method - how to add delay - please help

Hello All!

We are trying to create a small course using Unity. We have the script for it as XML. Parsed the XML and stored it. Now to present the text (conversation betwen student and teacher) , we are using two characters with speech bubbles. When we run the project, all the dialogues are getting displayed in a jiffy. We want the first text to be displayed then a delay, then the next dialogue/text.

here is the code in onGUI method

if (i < sceneArray.Length)
{

switch (sceneArray*.Type.ToString().Trim())*
{

case “presenter_text”:
//display text in speech bubble of presenter
string presenter_text = sceneArray*.SpeechText;*
DisplayText(“presenter”, presenter_text);

//Debug.Log(“switch-Inside presenter text–” + presenter_text);
//StartCoroutine(Example());
break;
case “listener_text”:
//text in student’s speech bubble
string student_text = sceneArray*.SpeechText;
DisplayText(“listener”, student_text);
//Debug.Log(“switch- listener_text—” + student_text);
_//StartCoroutine(Example());
break;
} //switch case ends here*_

} //if ends here
i++;
I have tried a lot but in all places the say onGUI cannot be delayed. I tried many methods but none are working. there are no errors. it is just that the text in the text boxes gets displayed and finishes the conversation in a second. I printed all the texts to console to see all is well on that side.
Our team is stuck with this since a day. Any help will be greatly appreciated.

use a coroutine with yield wait for seconds

1 Like
1 Like

Abandon OnGUI and move to the UI system. Use a coroutine to introduce delay.

2 Likes

Agreed, I find it quite frustrating to see so many people seemingly just choosing a 3-4 year old tutorial without knowing a lot of the content is deprecated.

1 Like

Thanks! That is what we ended up using. And it works like a charm.

Believe me, I looked up quite a lot, to see if there were any latest posts , but could find none, so had to make do with what was available.

1 Like