- Home /
How To Change Color Of Text On UI When It's Selected | Unity 4.6
How do I change the font's color when Normal/HighLighted/Pressed/Disabled in the new UI system for unity 4.6? The Button -> Transition -> Color Tint will just change the BUTTON'S color, and not the font itself. Any idea on how I could do that? :)
Thanks in advance, peace! :)
The font should change colour the way you've described it. I am assu$$anonymous$$g you have a normal text component then you've added a button to the text component? Then you've changed the tints accordingly. That should work fine.
Answer by amisane · Nov 19, 2016 at 07:03 AM
I achieved this with minimal effort by adding a script to my button and implementing ISelectHandler and IDeselectHandler
public class ButtonTextColorChangeScript : MonoBehaviour, ISelectHandler, IDeselectHandler {
void ISelectHandler.OnSelect(BaseEventData eventData)
{
gameObject.GetComponentInChildren<Text>().color = new Color(255, 255, 255, 255);
}
public void OnDeselect(BaseEventData eventData)
{
gameObject.GetComponentInChildren<Text>().color = new Color(0, 0, 0, 255);
}
}
I have implemented this however for some reason it only seems to work with setting the color to (0,0,0,255) if i want to use a different color its not working! :( any idea why?
Answer by UNZoOM · Mar 19, 2015 at 10:55 PM
To change the color of the text itself.
Select the Text under the Button in the canvas which looks like following :
And then you can change the color here as shown below :
Answer by DiegoSLTS · Mar 19, 2015 at 08:29 PM
You can do that making animation clips for each state (changing the background image and text color) and setting the Transition to Animation. That's the most flexible way of doing things with the Button component, each animation could affect multiple objects and values.
Another option would be to remove the Button component and add an Event Trigger component. With that component you can setup callbacks for each UI event, and those callbacks can trigger functions in any gameobject. This let you do more stuff than the "Transition -> Animation" method since you're not tied to animations, but it takes some extra work to set it all up.
Your answer
Follow this Question
Related Questions
Easily recolorable Button background textures 1 Answer
Find GUI Button and Assign Text 1 Answer
How to change text color on hover in new GUI? 10 Answers
Destory button on click and other problem 0 Answers
How do I invert the color of ui text to make it more readable, on a messy background? 4 Answers