我使用Unity 5.3.1。 我想要使用淡入淡出效果改变场景。LoadScene与衰落C#
一切工作,但是,我的新的场景为 “灰色” ......像这样:
相反的:
我的衰落:
public class Fading : MonoBehaviour {
public Texture2D fadeOutTexture;
public float fadeSpeed = 0.8f;
private int drawDepth = -1000;
private float alpha = 1.0f;
private int fadeDir = -1;
void OnGUI()
{
alpha += fadeDir * 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)
{
Debug.Log("BeginFade");
fadeDir = direction;
return fadeSpeed;
}
void OnLevelWasLoaded(int level)
{
Debug.Log("wasLoaded");
BeginFade(-1);
}
}
而且mycode的谁执行我的场景:
IEnumerator ChangeLevel()
{
float fadeTime = GameObject.Find("GM").GetComponent<Fading>().BeginFade(1);
yield return new WaitForSeconds(fadeTime);
SceneManager.LoadScene(scene);
}
而且我ChangeLevel函数的调用:
if (other.gameObject.name == "MenuController")
{
StartCoroutine(ChangeLevel());
}
谢谢!我会找到它! –