I am using the following code to fade from one scene to another, but it doesn't fade. It just loads the next scene without fading. I suspect there's something wrong with the image I'm using. I used a black .png image with dimensions 425×344 that I downloaded from Google. How can I solve this issue?
Fading.cs (I added this to an empty game object)
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);
}
In the script of the trigger object:
IEnumerator gameScene2() {
float fadeTime = GameObject.Find ("FadeObject").GetComponent<Fading>().BeginFade(1);
yield return new WaitForSeconds(fadeTime);
Application.LoadLevel("Scene2");
}
These are the image settings for the black .png image