Unity - change scene after specific time

前端 未结 1 635
清酒与你
清酒与你 2021-01-19 04:35

I am developing game for oculus Gear VR (to put in your consideration memory management ) and I need to load another screen after specific time in seconds



        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 05:15

    Yes, it is the correct way. Here's the sample code to display a countdown message:

    using UnityEngine;
    using System.Collections;
    
    public class Test : MonoBehaviour
    {
        bool loadingStarted = false;
        float secondsLeft = 0;
    
        void Start()
        {
            StartCoroutine(DelayLoadLevel(10));
        }
    
        IEnumerator DelayLoadLevel(float seconds)
        {
            secondsLeft = seconds;
            loadingStarted = true;
            do
            {
                yield return new WaitForSeconds(1);
            } while (--secondsLeft > 0);
    
            Application.LoadLevel("Level2");
        }
    
        void OnGUI()
        {
            if (loadingStarted)
                GUI.Label(new Rect(0, 0, 100, 20), secondsLeft.ToString());
        }
    }
    

    0 讨论(0)
提交回复
热议问题