面板应淡入,然后加载新场景

时间:2019-05-17 17:56:40

标签: c# unity3d coroutine

激活触发器后,面板应淡入,然后应加载新场景。不幸的是,这些事情中只有一种发生。

我希望一个接一个发生。

public void transitionpef()

{
    StartCoroutine(panelfadewhite());
}


public IEnumerator panelfadewhite()

{

    float ElapsedTime = 0f;
    float TotalTime = 2f;

   while (ElapsedTime < TotalTime)

    {
      ElapsedTime += Time.deltaTime;
      panel.color = Color.Lerp(new Color(1.0f, 1.0f, 1.0f, 0), new Color(1.0f, 1.0f, 1.0f, 1), (ElapsedTime / TotalTime));
      yield return new WaitForSeconds(3);
      SceneManager.LoadScene("selection_ui", LoadSceneMode.Single);
      yield return null;
    }

}

1 个答案:

答案 0 :(得分:3)

看起来您的退货错误了。试试这个:

public IEnumerator panelfadewhite()
{
    float ElapsedTime = 0f;
    float TotalTime = 2f;
    while (ElapsedTime < TotalTime)
    {
          ElapsedTime += Time.deltaTime;
          panel.color = Color.Lerp(new Color(1.0f, 1.0f, 1.0f, 0), new Color(1.0f, 1.0f, 1.0f, 1), (ElapsedTime / TotalTime));
          yield return null;
    }
    yield return new WaitForSeconds(3);
    SceneManager.LoadScene("selection_ui", LoadSceneMode.Single);
    yield return null;    
}