C# Unity 2D中场景之间的淡入淡出

C# Unity 2D中场景之间的淡入淡出,c#,android,C#,Android,我正在为Android开发一款游戏,我正在使用此代码通过一个按钮在两个场景之间淡入淡出: public class fading : MonoBehaviour { public Texture2D fadeOutTexture; public float fadeSpeed = 0.8f; private int drawDepth = -1000; private float alpha = 1.0f;

我正在为Android开发一款游戏,我正在使用此代码通过一个按钮在两个场景之间淡入淡出:

 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.g, GUI.color.b, alpha);
            GUI.depth = drawDepth; 
            GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), fadeOutTexture); }

        public float BeginFade (int direction) {
            fadeDir = direction;
            return (fadeSpeed); }

        void onLevelWasLoaded() {
            BeginFade (-1);

        }
    }
附加到UI按钮的代码:

public void gameScene2() {
        float fadeTime = GameObject.Find ("scene2Choose").GetComponent<fading>().BeginFade(1);
        yield return new WaitForSeconds(fadeTime);
        Application.LoadLevel("gameScene2");
    }
}
public void gameScene2(){
float fadeTime=GameObject.Find(“scene2Choose”).GetComponent().BeginFade(1);
产生返回新WaitForSeconds(fadeTime);
Application.LoadLevel(“gameScene2”);
}
}
我得到了这个错误: ArgumentException:方法返回类型不兼容


我做错了什么?

您必须编写一个
corroutine
,才能使上述功能正常工作。例如

IEnumerator gameScene2() {
    float fadeTime = GameObject.Find ("scene2Choose").GetComponent<fading>().BeginFade(1);
    yield return new WaitForSeconds(fadeTime);
    Application.LoadLevel("gameScene2");
}
IEnumerator游戏场景2(){
float fadeTime=GameObject.Find(“scene2Choose”).GetComponent().BeginFade(1);
产生返回新WaitForSeconds(fadeTime);
Application.LoadLevel(“gameScene2”);
}
然后在
按钮中单击
如下所示

start例程(gamescee2())

我已经添加了上面的代码,谢谢。当您说按钮单击时,您是指inspector中的On click()吗?我看不到StartCooutine选项。我已经读到我需要将StartRotine放入更新方法中,因此如何将我正在使用的按钮链接到该方法?您可以尝试以下方法: