Unity-在特定时间后更改场景 [英] Unity - change scene after specific time

查看:438
本文介绍了Unity-在特定时间后更改场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为oculus Gear VR (为了考虑内存管理)开发游戏,我需要在几秒钟的特定时间后加载另一个屏幕

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

void Start () {

    StartCoroutine (loadSceneAfterDelay(30));

    }

    IEnumerator loadSceneAfterDelay(float waitbySecs){

        yield return new WaitForSeconds(waitbySecs);
        Application.LoadLevel (2);
    } 

它工作得很好,

我的问题:

1-实现此目标的最佳做法是什么?

1- What are the best practices to achieve this?

2-如何为玩家显示计时器,以显示完成级别还剩下多少秒.

2- How to display timer for player showing how many seconds left to finish level.

推荐答案

是的,这是正确的方法.这是显示倒计时消息的示例代码:

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());
    }
}

这篇关于Unity-在特定时间后更改场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆