I am trying to make a fadeout/fadein scene change, but when I use the script I am using:
using UnityEngine;
using System.Collections;
public class SceneFade : MonoBehaviour
{
public Texture2D fadeOutTexture; //Overlaying texture screen
public float fadeSpeed = 0.8f; //Fade speed
private int drawDepth = -1000; //Texture's order in heirarchy
private float alpha = 1.0f; //Alpha from 0-1
private int fadeDir = -1; //Direction to fade -1 in or 1 out
void OnGUI()
{
alpha += fadeDir * fadeSpeed * Time.deltaTime; //Fade via direction and using time and speed to convert to framerate
alpha = Mathf.Clamp01(alpha); //clamps number between 0 and 1, for GUI.color doesn't support negatives
GUI.color = new Color (GUI.color.g, GUI.color.b, alpha); //Set alpha value
GUI.depth = drawDepth; //Put rectangle on top
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), fadeOutTexture); //Trigger fade
}
public float BeginFade (int direction) //Sets whether scene should fade in or out
{
fadeDir = direction;
return (fadeSpeed); //Return fadeSpeed to use
}
void OnLevelWasLoaded ()
{
BeginFade (-1); //Calls the function
}
}
it draws the texture over the screen, so it is always black. I can’t seem to find a way to sneak in code to make it transparent until the scene begins to change without breaking how the code works. How could I achieve this?