Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Sneer1 · Nov 19, 2014 at 08:31 PM · screenoculusfade

Application.LoadLevel with FadeOut

I'm testing some 3D GUIs with a oculus rift rig. And I was looking for a fadein/out script for the cameras. I found one script: Fade-in works great, but Fadeout doesn't work. I'm using triggers to load a new level. In this case the screen freezes and just loads the new level. Is there a way to use fade in general for all triggers / levels? Here's the Screen-Fader script (it uses 2 boxes to block both camera-vision):

 using UnityEngine;
 using System.Collections;
 
 public class Screenfader_level0 : MonoBehaviour {
     
         public float fadeSpeed = 1.5f;          // Speed that the screen fades to and from black.
         
         
         private bool sceneStarting = true;      // Whether or not the scene is still fading in.
         
         
         void Awake ()
         {
             // Set the texture so that it is the the size of the screen and covers it.
             guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
         }
         
         
         void Update ()
         {
             // If the scene is starting...
             if(sceneStarting)
                 // ... call the StartScene function.
                 StartScene();
         }
         
         
         void FadeToClear ()
         {
             // Lerp the colour of the texture between itself and transparent.
             guiTexture.color = Color.Lerp(guiTexture.color, Color.clear, fadeSpeed * Time.deltaTime);
         }
         
         
         void FadeToBlack ()
         {
             // Lerp the colour of the texture between itself and black.
             guiTexture.color = Color.Lerp(guiTexture.color, Color.black, fadeSpeed * Time.deltaTime);
         }
         
         
         void StartScene ()
         {
             // Fade the texture to clear.
             FadeToClear();
             
             // If the texture is almost clear...
             if(guiTexture.color.a <= 0.05f)
             {
                 // ... set the colour to clear and disable the GUITexture.
                 guiTexture.color = Color.clear;
                 guiTexture.enabled = false;
                 
                 // The scene is no longer starting.
                 sceneStarting = false;
             }
         }
         
         
         public void EndScene ()
         {
             // Make sure the texture is enabled.
             guiTexture.enabled = true;
             
             // Start fading towards black.
             FadeToBlack();
             
             // If the screen is almost black...
             if(guiTexture.color.a >= 0.95f)
                 // ... reload the level.
                 Application.LoadLevel();
         }
     }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Nov 19, 2014 at 08:40 PM

Like Jeff said your script will be wiped out when the new level is loaded. All you need is to out this line in your Awake function:

 DontDestroyOnLoad(gameObject);

Keep in mind that this will make the gameobject including all attached scripts and child objects to survive the level change. So when the level is loaded this object will be still there. In your case when you reload the same scene and the scene already contains that script you will end up with two instances and you get a new one each time you reload the scene.

I've written a little helper script some time ago that does all this out of the box. The script doesn't need to be attached to anything manually.

Comment
Add comment · 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
0

Answer by Sneer1 · Nov 24, 2014 at 11:28 PM

Thx, DestroyOnLoad works fine.

Bunny83: I have tried your global script. But I'm getting an error message for my levelselection script: Unknown identifier: 'AutoFade'. I have added AutoFade to my 3D Scene.

Comment
Add comment · Show 1 · 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 Uldeim · Nov 24, 2014 at 11:36 PM 0
Share

@Sneer1 - This should be a comment to Bunny83's answer. This isn't a forum; answers aren't guaranteed to stay ordered.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Oculus: Is player looking at Object A ? 1 Answer

Need help getting the screen to fade. 2 Answers

Make damage screen ui image 1 Answer

Fade Screen Transition After Death 1 Answer

FadeOut when enter Collider errors. 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