-1
\$\begingroup\$

I have a text mesh in my scene. I don't want the test to show right when the scene starts . I want to text to show up in the scene five or ten seconds later on the screen and than the text disappear after five seconds. I only got one error . Here is my script :

{

   using UnityEngine;
   using System.Collections;
   using UnityEngine.UI;
   
   public class oik : MonoBehaviour
   {
       private Text text;
       public float timeShown;
   
       void ShowMessage(string message, float timeToShow = 10)
       {
           StartCoroutine(ShowMessageCoroutine(message, timeToShow));
       }
       
       IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
       {
           while (timeShown < timeToShow)
           {
               timeShown += Time.deltaTime;
               yield return null;
           }
 
           text.text = " The Reqiure Score is 1700" ;
       }
   }

}

\$\endgroup\$
  • \$\begingroup\$ What one error do you get? \$\endgroup\$ – Tristan Kreuziger Aug 31 '16 at 22:16
0
\$\begingroup\$

You would call the ShowMessage method in your class's Start method. That way the timer will start and after ten seconds the text is displayed.

To remove it after another five seconds you add below text.text = ...:

timeShown += Time.deltaTime;
if (timeShown >= timeToShow + 5)
    text.text = "";
| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.