Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unity | how to make something happen after 10 seconds without delaying game

hello there I have been having trouble figuring out this problem. Basically I want to make something happen after 10 seconds without delaying the start function or slowing down the frame using the update function. I’m ort of new to unity so if there is anything that I would need to provide tell me. Thanks!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There are lots of ways! Here are a few examples:

  1. Use a Unity Coroutine (https://docs.unity3d.com/Manual/Coroutines.html)
    void Start()
    {
        StartCoroutine(DoSomethingAfterTenSeconds());
    }

    IEnumerator DoSomethingAfterTenSeconds()
    {
        yield return new WaitForSeconds(10);

        // now do something
    }
  1. Use FixedUpdate or Update to wait 10 seconds:
    private float _delay = 10;

    public void FixedUpdate()
    {
        if (_delay > 0)
        {
            _delay -= Time.fixedDeltaTime;

            if (_delay <= 0)
            {
                // do something, it has been 10 seconds
            }
        }
    }
  1. Use async/await instead of coroutines (https://forum.unity.com/threads/c-async-await-can-totally-replace-coroutine.1026571/)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading