• 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 /
  • Help Room /
avatar image
0
Question by Danor · Nov 28, 2015 at 04:06 PM · uiunity5colorbuttonshighlight

After changing multiple buttons highlight color, buttons dissapear on click.

I want to give my players the option of changing some of the menu colors incl the button highlights and even though it took me quite some headscratching i made a function that succesfully changes the highlights of all buttons in my list but there's a weird side effect, now buttons dissapear on click and then briefly show the highlight while re-appearing back to normal state.

I don't understand what's going on at all and there's no errors.

All buttons have the default Color Tint Transition And here's my code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 
 public List<Color> Colors = new List<Color>();
 public List<Button> Buttons = new List<Button>();
 
 public void ButtonHighlights(int colorSelected){
         int count = Buttons.Count;
         while(count != 0){
             count--;
             Button b = Buttons[count].GetComponent<Button>(); 
             ColorBlock cb = b.colors;
             cb.highlightedColor = Colors[colorSelected];
             b.colors = cb;
         }
     }


If anyone has any ideas, please share them! The code is based on code by @PeterMu Link: http://answers.unity3d.com/questions/792008/how-to-change-normal-color-highlighted-color-etc-i.html Thanks in advance.

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
Best Answer

Answer by Danor · Dec 02, 2015 at 01:10 AM

I feel really silly now but the problem wasn't script related, i set the A value of the colors in "Colors" list, in the editor to 0 instead of 255 for some reason.

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 DannyMen · Sep 20, 2017 at 02:17 AM

thanks a lot for the commet you save me the night check the alpha chanel

using UnityEngine.UI;

 public Color newColor;

 void Start(){

      Button miBoton = this.GetComponent<Button>(); 
      ColorBlock cb = miBoton.colors;
         cb.highlightedColor = newColor;
      miBoton.colors = cb;        
 }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

45 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

Related Questions

Buttons not highlighting while dragging 0 Answers

UI Button not accurate 1 Answer

error CS1736: The expression being assigned to optional parameter `i' must be a constant or default value 0 Answers

GearVR Unity 5.5 Touchpad Input Button Press Inconsistent? 0 Answers

Sketchy looking buttons in android 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges