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 NatalSJ · Jan 26, 2017 at 09:15 AM · javascriptguibugfadeout

Fade out effect isn't working if loaded at the second time.

  #pragma strict
  
  // FadeInOut
  
  var fadeTexture : Texture2D;
  var fadeSpeed = 0.2;
  var drawDepth = -1000;
  
  private var alpha = 1.0; 
  private var fadeDir = -1;
 
  function OnGUI()
  {  
      alpha += fadeDir * fadeSpeed * Time.deltaTime;  
      alpha = Mathf.Clamp01(alpha);   
      
      GUI.color.a = alpha;
      
      GUI.depth = drawDepth;
      
      GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeTexture);
  }


That's my script that is attached on the Main Camera. A plain black texture is attached to fadeTexture.

This works whenever I start the game from the main menu. But when I start a level and I click a button where it takes me back to the main menu, the "fade out" effect doesn't work anymore, the plain black picture is just there. Covering the whole GUI.

I have two different scenes. Main Menu and the level of the game.

Advanced thank you guys!

EDIT: By the way, for my BackToMainMenu script. I use

 Application.LoadLevel(0);
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 hassanyawar · Jan 26, 2017 at 10:38 AM

I think the culprit is this line:

 alpha += fadeDir * fadeSpeed * Time.deltaTime; 

The first time it works fine but second time it doesn't because 'alpha' retains its previous value. Every time you want fade out you need to reset the the value of 'alpha'. Try to reset it and check it then if its working or not.

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 NatalSJ · Jan 28, 2017 at 07:57 PM 0
Share

I tried doing that by putting this script in void Start()

 alpha = 1.0;

But it's still the same.

avatar image hassanyawar NatalSJ · Feb 01, 2017 at 10:33 AM 0
Share

Is your main menu and game level in a same scene or separate scene?

avatar image
0

Answer by mcneproj · Feb 01, 2017 at 02:00 PM

Call the fadeOut() function on the UI button you use to go back to the menu.

 public var fadeOutTexture : Texture2D;
     public var fadeSpeed = 0.3;
      
     var drawDepth = -1000;
      
      
     private var alpha = 1.0; 
      
     private var fadeDir = -1;
     
     function Start(){
         alpha=1;
         fadeIn();
     } 
     
     function OnGUI(){
      
         alpha += fadeDir * fadeSpeed * Time.deltaTime;    
         alpha = Mathf.Clamp01(alpha);    
      
         GUI.color.a = alpha;
      
         GUI.depth = drawDepth;
      
         GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
     }
       
     function fadeIn(){
         fadeDir = -1;    
     }
       
     function fadeOut(){
         fadeDir = 1;    
     }
      
     

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

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

6 People are following this question.

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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can't get 4.6 GUI Button to Load Scene (Solved) 1 Answer

Gui Text Script 4 Answers

GUI Button Disappearing 1 Answer

Select a game object and perform actions using GUI.Button (EventTrigger) 2 Answers


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