Unity WaitForSeconds 不工作 c#

Unity WaitForSeconds not Working c#

我在 Unity 中遇到了问题。我没有更改我的脚本或场景中的任何内容,但它自己发生了问题。我很困惑,粒子和动画师也不起作用。当我通过按钮重新加载场景时,所有脚本、粒子和动画师都可以正常工作。

void Start(){
        if (PlayerPrefs.GetString ("Intro") == null || PlayerPrefs.GetString ("Intro") != "1")
            Application.LoadLevel ("dragonIntro");

        if (PlayerPrefs.GetInt ("Ads") == null)
            PlayerPrefs.SetInt ("Ads", 0);

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        if(PlayerPrefs.GetString("language")==""){
            PlayerPrefs.SetString("language",Application.systemLanguage.ToString());
            Application.LoadLevel(Application.loadedLevel);
        }
        Debug.Log ("test");
        StartCoroutine(rainMe());

 }




IEnumerator rainMe(){
        Debug.Log ("test2");
        float myWait = Random.Range(3f,6f);
        Debug.Log ("test3");
        yield return new WaitForSeconds(myWait);
        Debug.Log ("test4");
        isRain = 0;
        SendMessage("lightMe");
    }

控制台中似乎没有 Test4。

注意:我尝试用我的恢复文件修复它,但问题仍然存在

好的!我解决了 problem.timeScale 引起的问题。

遇到这个问题的人可以通过这个答案轻松解决

void Start(){
        Time.timeScale= 0;
        Time.timeScale = 1;
}

未来的提示,不要为暂停项目操纵 Time.timeScale。我以惨痛的方式吸取了教训,它做了一些时髦的事情。最好的办法是保存所有对象的状态,或者有一个静态 public 变量或 class 来模拟状态机。如果是暂停状态(全局静态),则跳过Update() LateUpdate() FixedUpdate()中的内容。你明白了。

我的解决方法是,我重新设置了Time.timeScale,先设置“0”,然后再设置1

void Start(){
        Time.timeScale= 0;
        Time.timeScale = 1;

}