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 Chedora · Feb 24, 2015 at 10:57 AM · uiguibuttonimage

Buttons become invisible when changing color (on Button or on Image) in script

I'm trying to make a UI that can add buttons to a panel and change their colors based on the player's progress in the game. I have a prefab button that I instantiate to create the list of buttons. Here's where I set up the buttons:

 foreach(Quest q in QuestManager.questManager.quests){
             GameObject buttonObj = Instantiate(questButtonPrefab) as GameObject;
             buttonObj.transform.SetParent(gameObject.transform.GetChild(0), false);
 
             RectTransform rt = buttonObj.GetComponent<RectTransform>();
             rt.localPosition = new Vector3(0, buttonY, 0);
             rt.sizeDelta = buttonSize;
             buttonY -= (int)(buttonSize.y);
 
             Button button = buttonObj.GetComponent<Button>();
             button.onClick.AddListener(() => questButtonClicked(q.id));
             button.transition = Selectable.Transition.None;
             questButtons.Add(button);
 
             Text buttonText = button.transform.GetChild(0).gameObject.GetComponent<Text>();
             buttonText.text = q.questName;
 
             Image buttonImage = buttonObj.GetComponent<Image>();
 
             if(q.completed){
                 //button.colors = completedColorBlock;
                 buttonImage.color = completedColor;
             } else if(q.started){
                 //button.colors = inProgressColorBlock;
                 buttonImage.color = inProgressColor;
             } else if(q.isAvailable()){
                 //button.colors = availableColorBlock;
                 buttonImage.color = availableColor;
             } else {
                 //button.colors = unavailableColorBlock;
                 buttonImage.color = unavailableColor;
             }
         }

When I try to change the colors, either on the image or the button components, the buttons disappear, but they still work if you click on where they should be. The Text object (child of the button) still displays. This only happens when I try to change the colors in the script, and works as expected when I change the colors in the editor while the game is running. Can anyone explain what is going on here?

Comment
Add comment · Show 2
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 Chedora · Feb 24, 2015 at 02:41 PM 1
Share

That was my issue. Thank you for the reply!

avatar image NoseKills · Feb 24, 2015 at 04:58 PM 0
Share

I converted the comment to an answer. Please click the checkmark next to it to mark this question answered.

1 Reply

· Add your reply
  • Sort: 
avatar image
18
Best Answer

Answer by NoseKills · Feb 24, 2015 at 11:16 AM

If i remember correctly I've had similar problems because I think the Inspector likes to default the alpha of color variables to 0. If you make public Color variables, be sure to drag their alpha value up in inspector

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 pushxtonotdie · Jan 05, 2017 at 10:14 PM 2
Share

$$anonymous$$y issue was the color$$anonymous$$ultiplier was set to zero as well!

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

39 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

Related Questions

Best Button for UnityGame 2D 1 Answer

Gui.Button Image in Button - error 1502 and 1503 0 Answers

UI Button multiple parameters 6 Answers

Image in Button is cut (New UI) 2 Answers

Transparent Images as UI 0 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