Coder221
Coder221

Reputation: 1433

Making text in text mesh stay for few seconds

I want to display my text for 3 seconds, so I did the following, but it is just blinking and disappearing.

  void Start () {
        Invoke("ShowInfoText", 2f);
    }

void ShowInfoText()
{
    infoText.gameObject.SetActive(true);

    infoText.text = "Welocme!";

    Invoke("DisableInfoText", 5f);
}

void DisableInfoText()
{
    infoText.gameObject.SetActive(false);
}

How do I make the text to stay for 3 seconds?

Upvotes: 1

Views: 56

Answers (1)

Iggy
Iggy

Reputation: 4888

You could try InvokeRepeating.

public void InvokeRepeating(string methodName, float time, float repeatRate);

You could also use a Coroutine:

void Start ()
{
    StartCoroutine(DoTextShow());
}

IEnumerator DoTextShow()
{
    infoText.gameObject.SetActive(false);
    yield return new WaitForSeconds(2f);
    infoText.gameObject.SetActive(true);
    yield return new WaitForSeconds(3f);
    infoText.gameObject.SetActive(false);
}

Upvotes: 1

Related Questions