- Home /
 
               Question by 
               byurocks23 · Nov 21, 2014 at 07:41 PM · 
                javascriptuibuttoncolor  
              
 
              Unity 4.6 UI change button color when pressed. -Javascript
In want to be able to press a UI button and have it change color. I am doing it with script and nothing I've tried has worked. In javascript, what is the code that will change the color of a button?
               Comment
              
 
               
              You do realise the button component has a transition that let's you do this without a script.
 
               Best Answer 
              
 
              Answer by Eric5h5 · Nov 21, 2014 at 08:34 PM
 GetComponent(Button).colors.normalColor = Color.green;
Sorry I am very new at unity so this might be obvious. When I run it, I get an error that says
Assets/RadioButtons.js(7,22): BCE0005: $$anonymous$$ identifier: 'Button'.
I figured it out. It should be GetComponent(UI.Button).colors.normalColor = Color.green;
That is if you forgot to add:
 using UnityEngine.UI;
otherwise it is as shown n the answer.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                