Change Button Color in Script

0 votes
asked Mar 21, 2016 in Help by anonymous
What's the best way to change the button color in a script? I'm attempting to do it, but it appears that my value is being overridden by the Material Button Script.

1 Answer

0 votes
answered Mar 25, 2016 by admin (31,720 points)
selected Mar 28, 2016 by admin
 
Best answer

Hello!

The best way to do that is using the SetGraphicColor method on your MaterialButton, like so:

[SerializeField] private MaterialButton m_Button;

public void ChangeButtonColor()
{
	m_Button.materialRipple.SetGraphicColor(MaterialColor.red500, false);
}

The first parameter is the color of the button.
The second parameter will animate (if true) or not (if false) the transition from the current color to the color you specified in the first parameter.

Have a great day ;) 

Welcome to MaterialUI support! Ask us anything :)
...