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
0
Question by jeebolion · Aug 17, 2020 at 06:01 PM · uicoroutinetransparency

Mouse Idle UI question

How might I refactor my code to allow a mouse-idle Coroutine take into account whether a submenu is currently active or not?

In my program, I have a couple of menu buttons that call a submenu (an object and its children, repurposed for each menu "type"). As well, I have a coroutine that changes the UI's alpha to transparent after a period of mouse inactivity (and back to opaque on movement). I am trying to:
1. Reuse the same Fade() coroutine for my submenu for when it is activated/deactivated.
2. Have the ability to include/exclude the submenu from Fade() as a whole dependent on if it is activated.

 bool boop;
     public void HideSUB()
     {
         boop = true;
         if (GetComponent<UIHandling>().SubOn == false)
         {            
             StartCoroutine(Fade(true));
         }
         else
             StartCoroutine(Fade(false));
         boop = false;
     }
     
 
 
     IEnumerator Fade(bool fading)
     {
         CanvasGroup UIalpha = GameObject.Find("UIPanel").GetComponent<CanvasGroup>();
         CanvasGroup SUBalpha = GameObject.Find("Submenu").GetComponent<CanvasGroup>();
 
         
         
 
         // Fade Out
         if (fading == true)
         {
             if (boop == false)
             {
                 while (UIalpha.alpha > 0) //while opaque
                 {
                     UIalpha.alpha -= Time.deltaTime / 2; //fades over time    
                     if (GetComponent<UIHandling>().SubOn == true)
                     {
                         while (SUBalpha.alpha > 0)
                         {
                             SUBalpha.alpha -= Time.deltaTime / 2;
                         }
                     }
 
                     yield return null;
                 }
             }
             else
             {
                 while (SUBalpha.alpha > 0)
                 {
                     SUBalpha.alpha -= Time.deltaTime / 1;
                 }
                 yield return null;
             }
         }
 
         // Fade In
         else if (fading == false)
         {
             if (boop == false)
             {
                 while (UIalpha.alpha < 1)
                 {
                     UIalpha.alpha += Time.deltaTime / 1;
                     if (GetComponent<UIHandling>().SubOn == true)
                     {
                         while (SUBalpha.alpha < 1)
                         {
                             SUBalpha.alpha += Time.deltaTime / 1;
                         }
                     }
 
                     yield return null;
                 }
             }
             else
             {
                 while (SUBalpha.alpha < 1)
                 {
                     SUBalpha.alpha += Time.deltaTime / 1;
                 }
                 yield return null;
             }
         }




Using the (non-working) code above, I tried to include some while/else/ifs into my working Fade() to incorporate the changes I'm trying to make above. I keep getting NullReferenceExceptions at the line checking if my bool "SubOn" is true/false.

Any help would be appreciated! Thanks.

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

0 Replies

· Add your reply
  • Sort: 

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

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

Canvas with mask and transparent image 1 Answer

Use stencil buffer to hide objects with same shader? 1 Answer

Create a countdown in C# (inside Coroutine) 2 Answers

Instance not found only when using button press to execute function,Canvas instance not found when executing function via button press 0 Answers

selective transparency 3 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