按下按钮时如何使新场景淡入?

How can I make a new scene fade in when a button is pressed?

我遵循了 Brackeys 的教程(您可以观看 here),了解如何在场景之间淡入淡出。我尽我所能按照教程进行操作,但是,当我 运行 我的场景时,场景淡入(这不应该发生)并且当我按下按钮时,没有任何反应(但场景应该改变).

我的代码有什么问题?如何修复它以便在按下按钮时新场景淡入?这是我的代码:

changeScene.cs

using UnityEngine;
using System.Collections;

public class changeScene : MonoBehaviour {

public IEnumerator changeToGameScene () {

    float fadeTime =     GameObject.Find("managerObject").GetComponent<fadeScript>().BeginFade(1);
    yield return new WaitForSeconds(fadeTime);
    Application.LoadLevel("gameScene");

}

}

fadeScript.cs

using UnityEngine;
using System.Collections;

public class fadeScript : MonoBehaviour {


// All Variables
public Texture2D fadeOutTexture;
public float fadeSpeed = 0.8f;

private int drawDepth = -1000;
private float alpha = 1.0f;
private int fadeDirection = -1;

void OnGUI () {

    alpha += fadeDirection * fadeSpeed * Time.deltaTime;
    alpha = Mathf.Clamp01(alpha);

    GUI.color = new Color (GUI.color.r, GUI.color.g, GUI.color.b, alpha);
    GUI.depth = drawDepth;
    GUI.DrawTexture ( new Rect (0, 0, Screen.width, Screen.height),     fadeOutTexture );
}

public float BeginFade (int direction) {

    fadeDirection = direction;
    return (fadeSpeed);

}

void OnLevelWasLoaded () {

    BeginFade (-1);

}

}

您可以尝试在场景顶部放置一个面板。 然后,使用动画组件,创建一个不透明度降低的新动画。事实上,你可以让按钮调用这个动画。在动画结束时,您可以添加一个事件来调用将销毁面板的函数。 希望对你有帮助。