Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by El-Deiablo · Jul 02, 2016 at 09:28 AM · scene-loadingscene-switchingfadeoutfadein

SceneFader

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 (https://www.youtube.com/watch?v=0HwZQt94uHQ), but ran into this issue - http://answers.unity3d.com/questions/1210640/coroutine-issue-1.html

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??

[1]: /storage/temp/73340-screen-shot-2016-07-02-at-112421-am.png

I would really appreciate any help.

screen-shot-2016-07-02-at-112421-am.png (32.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aditya · Jul 02, 2016 at 01:27 PM

simply create a UI panel with a image of color you want your scene to fade in and then use the below script ... DO NOT JUST COPY PASTE THE WHOLE CODE, WRITTEN WITHOUT EDITOR IN FRONT

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class fadeScene : Monobehaviour{
     public Image panelObject;
 
     void YesQuit(){
         panelObject.CrossFadeAlpha(1f, 0.2f, true);
         Invoke("loadNextScene", 0.3f);
     }
     void loadNextScene(){
         SceneManger.LoadScene("Title Menu");
     }
 }

Learn more about CrossFadeAlpha Here

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image El-Deiablo · Jul 02, 2016 at 03:47 PM 0
Share

Thank for getting back to me! I tried what you said, but the fade doesn't work and the scene does not change. The scene changes once Resume is pressed, but no fade. Here's my updated code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Scene$$anonymous$$anagement;
 using UnityEngine.UI;
 
 public class PausePanel : $$anonymous$$onoBehaviour {
 
     //public GUITexture overlay;
     //public float fadeTime;
 
     public Slider audioSlider;
     public Slider sensitivitySlider;
 
     private Player instance;
 
     public GameObject AreYouSureYouWantToQuit;
     public GameObject AreYouSureYouWantToRestart;
 
     public GameObject HowToPlayPanel;
     public GameObject SettingsPanel;
 
     public static bool isPaused=false;
 
     public Text highScoreText;
     public Text goldTeethText;
 
     public GameObject pause$$anonymous$$enuCanvas;
 
     public Image panelObject;
 
     //private bool home = false;
     //private bool restart = false;
     
     // Update is called once per frame
     void Update () {
         
         if (isPaused == true) {
 
             pause$$anonymous$$enuCanvas.SetActive (true);
             Time.timeScale = 0f;
 
         } else if (isPaused==false && TimeChangingPowerUp.Active == true) {
 
             pause$$anonymous$$enuCanvas.SetActive(false);
             Time.timeScale = 0.5f;
 
         }
 
         else {
 
             pause$$anonymous$$enuCanvas.SetActive(false);
             Time.timeScale = 1f;
 
         }
             
     }
 
     public void Resume(){
 
         isPaused = false;
         SettingsPanel.SetActive (false);
         HowToPlayPanel.SetActive (false);
         AreYouSureYouWantToRestart.SetActive (false);
         AreYouSureYouWantToQuit.SetActive (false);
 
     }
 
     public void Restart(){
 
         AreYouSureYouWantToRestart.SetActive (true);
 
     }
 
     public void YESRESTART(){
 
         //restart = true;
         panelObject.CrossFadeAlpha (1f, 0.2f, true);
         Invoke ("loadNextScene", 0.3f);
         //Scene$$anonymous$$anager.LoadScene ("Gameplay");
         //SceneFader.instance.LoadLevel("Gameplay");
         //StartCoroutine (SceneFaderGamePlay());
 
     }
 
     public void NEVERRESTART(){
 
         AreYouSureYouWantToRestart.SetActive (false);
 
     }
 
     public void Home(){
 
         AreYouSureYouWantToQuit.SetActive (true);
 
     }
 
     public void YESQUIT(){
 
         //home = true;
         panelObject.CrossFadeAlpha (1f, 0.2f, true);
         Invoke ("loadNextScene", 0.3f);
         //SceneFader.instance.LoadLevel("Title $$anonymous$$enu");
         //Scene$$anonymous$$anager.LoadScene ("Title $$anonymous$$enu");
         //StartCoroutine (SceneFaderHome());
         //StartCoroutine(FadeToClear());
 
     }
 
     void loadNextScene(){
 
 
             Scene$$anonymous$$anager.LoadScene ("Title $$anonymous$$enu");
 
 
         /*if (restart==true) {
 
             Scene$$anonymous$$anager.LoadScene ("Gameplay");
 
         }*/
 
     }
avatar image aditya El-Deiablo · Jul 04, 2016 at 05:17 AM 0
Share

i see nothing wrong with this updated code if your both YESRESTART and YESQUIT getting called, in this code i can't see these methods being called anywhere so i m assu$$anonymous$$g that your calling them either from UI buttons or some external script .... use debugs in these functions and make sure that they are getting called or not ... it is strange if this script is not working because you have just two lines here, one that is fading the panel's alpha and other that is loading the scene ... and make sure to keep the alpha of fader panel to zero on scene start

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

43 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fadeout Issue 0 Answers

Moving to next scene takes large time to load 1 Answer

Load 2 scenes at once throuh scipt 0 Answers

alpha value not changing(gradual decrease) during runtime 1 Answer

Display a GameOver scene then restart the game 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges