I’m curious as to how you can change to color of a button through a script in the new UI in Unity 4.6.
You have two ways to do this :
- Change the button’s image color
- Change transition’s color tint
Examples :
(1)
using UnityEngine.UI;
//...
Color buttonImageColor = gameObject.GetComponent<Image>().color;
buttonImageColor = new Color(1, 1, 1, 0.5f); // Some color
(2)
using UnityEngine.UI;
//...
ColorBlock colorTint = gameObject.GetComponent<Button>().colors;
colorTint.normalColor = new Color(1, 1, 1, 0.5f); // Some color
Note :
The 2nd way alters the button’s image to allow color variance when hovering the button, click it, etc…