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.
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.
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;
}