Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 LucrativeOne · Nov 24, 2021 at 11:45 AM · bug-perhapsnoobfade

Simple fade script unexpectedly fading all UI elements,Simple Fade script unexpectedly fading all UI elements

hey guys, I have this script I made (pulled off the internet) to fade my announcement box when it is active. When it is done fading, I wanted to then deactivate it, and reset the alpha channel. When I testing the following code, when the announcement box was set active, all objects in my UI canvas ALL fade out... I wouldn't assume this is expected behavior, but I am a noobie...
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class Announcements : MonoBehaviour
 {
     public Text announcementText;
 
     private Color alphaColor;
     private float timeToFade = 3.0f;
 
 
     // Start is called before the first frame update
     void Start()
     {
         alphaColor = this.gameObject.GetComponent<Image>().material.color;
         alphaColor.a = 0;
     }
 
     // Update is called once per frame
     void Update()
     {
         if (this.gameObject.activeInHierarchy == true)
         {
         
             this.gameObject.GetComponent<Image>().material.color = Color.Lerp(this.gameObject.GetComponent<Image>().material.color, alphaColor, timeToFade * Time.deltaTime);
 
         }
 
         //something about can select more than one enemy with this skill, maybe even quips from bosses
 
     }
 }

why is this code fading out all of my UI elements on the canvas!! what is the solution to this problem? My announcement box is not the only thing with the image component, but it is the only object with this script attached, and even my silders are all fading away. i also tried to replace this.gameobject with gameobject.find("announcementbox") but that didnt fix it either. :(

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 mryuri666 · Nov 24, 2021 at 12:33 PM

try to instantiate a public GameObject Announcement ; and then use Announcement.GetComponent instead os this.Gameobject.GetComponent (Dont forget to assign gameobject in inspector)

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 mryuri666 · Nov 24, 2021 at 12:33 PM 0
Share

@LucrativeOne

avatar image LucrativeOne · Nov 24, 2021 at 03:03 PM 0
Share

Thanks for the quick reply @mryuri666 before bed last night I tried yoinking some scripts I didn't understand from the interwebs, to no avail. I still have the exact script in the original question, and will be modifying it per your instructions.
1. After creating public GameObject Announcement, 2. dragging the AnnouncementBox into the new slot in the script in the inspector (script which is on AnnouncementBox itself) 3. replacing all of this.gameObject with new Announcement variable 4. Results in no change in behavior, as far as i can tell, all objects in hierarchy fade out, even ones not children of this exact UICanvas

I am lost, but touching component is confusing me. After everything fades away, and I check on the faded image's Image component (Including my AnnouncementBox with script attached), the color pop up window says that the alpha channel is 255.

FURTHERMORE after I exit playmode, those game objects dont reappear! They actually stay faded, and I have to close and reopen Unity to see them again!

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

135 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

Related Questions

Can't see EmptyObject in scene viewer,Can't See Empty Object in Scene View 3 Answers

Code not working right for puzzle game 2 Answers

iTween CameraFade not working in some cases (related to camera's cullingMask) 3 Answers

Wait and fading script 1 Answer

Fade texture on collision/trigger with certain tag or layer? 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