I want to change a UI Button’s color from 4D9289FF to 009BFFFF and back in a C# script. I see there is a variable called Button.colors, but I don’t know how to interact with/change it.
Can anyone help?
Note: I may not be able to respond to this post until a few hours before this time tomorrow.
From my understanding you cant pass a hex code only RGBA. The script is untested but you should get the idea.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ColorSelector : MonoBehaviour {
//Reference to button to access its components
private Button theButton;
// get the Transitions of the Button as its pressed
private ColorBlock theColor;
// Use this for initialization
void Awake () {
theButton = this.GetComponent<Button>();
theColor = this.GetComponent<Button>().colors;
}
public void ButtonTransitionColors()
{
theColor.highlightedColor = new Color(77, 146, 137);
theColor.normalColor = new Color(0, 155, 255);
theColor.pressedColor = new Color(77, 146, 137);
theButton.colors = theColor;
}
}
Ok thanks, I will try that at next opportunity