繁体   English   中英

在C#Unity 3D中延迟负载级别

[英]Delaying load level in c# unity 3d

我创建了一些代码,该代码打算在用户完成该操作后20秒钟加载我的下一个级别,但是我收到一条错误消息“需要对象引用才能访问静态函数”,但是我需要该函数是静态的才能当我的直升机门打开并且用户可以乘坐直升飞机时,请调用它。 有人可以帮忙吗?

    using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {


    static bool _hasPlayerWon = false;

    public static bool HasPlayerWon {get{return _hasPlayerWon;}}

    Health _playerHealth;




    public static void WinPlayer()
    {

        _hasPlayerWon = true;
        Invoke("loadSplash",20.0f);

    }


    void loadSplash ()
    {
        Application.LoadLevel("splash1");

    }


}

创建一个包含对GameManager的引用的字段,并使用触发加载的方法调用协程。

像这样:

static private GameManager instance;

void Awake()
{
    instance = this;
}

public static void WinPlayer()
{
    _hasPlayerWon = true;
    instance.LoadLevel();
}

private void LoadLevel()
{
  StartCoroutine( LoadCo() );
}

private IEnumerator LoadCo()
{
  yield return new WaitForSeconds( 20.0 );

  Application.LoadLevel("splash1");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM