R
R
readrain2022-04-03 16:10:44
C++ / C#
readrain, 2022-04-03 16:10:44

How to make text appear after some time in the game?

Hello, I have a question. How to make text appear after some time in the game?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GFX Data, 2022-04-03
@readrain

public GameObject text;

void Start()
{
    text.SetActive(false);
    const float DELAY = 5f;
    Invoke("ShowText", DELAY);
}

void ShowText()
{
    text.SetActive(true);
}

F
freeExec, 2022-04-03
@freeExec

You set the time of appearance and every frame you check if it has come yet.

B
BurovAlex88, 2022-04-04
@BurovAlex88

I like working with async/await Task.Yield()
the most. The biggest plus of this approach is that all timings and counters and other auxiliary variables remain inside the function.

private static async void SaveByTimeout()
        {
            var timer = 0f;
            var timeout = 5 * 60;
            while (IsSaveByTimeout)
            {
                if (timer >= timeout)
                {
                    timer = 0;
                    Save();
                }

                await Task.Yield();
                timer += Time.deltaTime;
            }
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question