I am extremely frustrated right now! I have done days of research on forums, unity tuts / answers, google, and youtube and have no luck getting a scenefader to work. All of the tutorials go show you how to make scene faders for level progression. My game is a high score game and I have a restart button, home button, and gameover scene currently that I would like to incorporate a fade effect with. I can’t believe the simplest things are giving me trouble. I am so close to finishing this game!
I got close with this tutorial (How to Fade Between Scenes in Unity - YouTube), but ran into this issue - Coroutine Issue - Questions & Answers - Unity Discussions
I have tried creating an image and changing the alpha manually when a new scene is loaded (using a bool if (scenechanged == true), but there was no effect.
What can I do?
This is how my scenechanging is setup:
public void Home(){
AreYouSureYouWantToQuit.SetActive (true);
}
public void YESQUIT(){
//SceneFader.instance.LoadLevel("Title Menu");
sceneChanged=true;
SceneManager.LoadScene ("Title Menu");
//StartCoroutine (SceneFaderHome());
//StartCoroutine(FadeToClear());
}
Here’s some of the other code I’ve tried:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SceneFader : 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){
fadeDir = direction;
return (fadeSpeed);
}
void OnLevelWasLoaded(){
BeginFade (-1);
}*/
public static SceneFader instance;
[SerializeField] private GameObject fadePanel;
[SerializeField] private Animator fadeAnim;
// Use this for initialization
void Awake () {
MakeSingleton ();
}
// Update is called once per frame
void Update () {
}
void MakeSingleton(){
if (instance != null) {
Destroy (gameObject);
} else {
instance = this;
DontDestroyOnLoad (gameObject);
}
}
public void LoadLevel (string level){
StartCoroutine (FadeInOut (level));
}
IEnumerator FadeInOut(string level){
fadePanel.SetActive(true);
fadeAnim.Play("SceneFadeIn Animation");
yield return new WaitForSeconds (1f);
SceneManager.LoadScene(level);
fadeAnim.Play("SceneFadeOut Animation");
yield return new WaitForSeconds (0.7f);
fadePanel.SetActive(false);
}
}
This image goes with the above code (that is not commented out) and again led to the null reference error??
I would really appreciate any help.