Hello, I just started using Unity a couple of days ago, and I think I’m starting to get the hang of it, but not really.
Anyways, I’ve created this script to fade my scenes in and out, and it works when I preview the scene, but not when I build the game, or when I preview the game as a whole in the editor.
Here’s my C# script:
//this is our boolean to control when we want to fade out
public static bool nextScene;
public float duration = 0.5f;
//our actual texture
public Texture image;
//create our GUI so that it will always draw on top
void OnGUI () {
//draw above our other guis
GUI.depth = 0;
fadeIn ();
//now create our gui texture
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height),
image);
}
// Use this for initialization
void Start ()
{
nextScene = false;
}
// Update is called once per frame
void Update ()
{
if (nextScene) {
fadeOut ();
}
}
//function for fading in
void fadeIn(){
GUI.color = Color.Lerp(Color.black, Color.clear, Time.time * duration);
}
//function for fading out
void fadeOut(){
GUI.color = Color.Lerp(Color.clear, Color.black, Time.time * duration);
}
any help is appreciated, as I’ve been trying to figure this out for a while. Thank you!