- Home /
How do I access a button component
Hi all,
In my scene I have a few objects with buttons. I want to change the color of these buttons depending on the options the player chooses. How can I do this?
Answer by Neamtzu · Mar 26, 2015 at 02:40 PM
If you're using the new UI system, you should get the button component of those buttons like this:
Button yourButton = yourObject.GetComponent<Button>();
Then you can access the color properties like this:
yourButton.colors.normalColor = newColor;
Here you can find all the variables you can change through colors property : http://docs.unity3d.com/ScriptReference/UI.ColorBlock.html
You are correct. However, you need using UnityEngine.UI;
or else you're not able to make a Button variable. That's why it didn't work for me :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
GameObject.Destroy(gameObject) does not destroy capsules 2 Answers
Changing anchor positions on UI? 0 Answers
Checking if Button is not pressed 1 Answer