I just want to change the color of a button in c# code

I just want to change

this value in code

GetComponent<Image>().color = Color.green
1 Like

I tried that and got :
Assets/changeColor.cs(8,30): error CS0246: The type or namespace name `Image’ could not be found. Are you missing a using directive or an assembly reference?

ps
can I do word wrap in the console window?

GetComponent<UnityEngine.UI.Image>().color = Color.red;

ps
no

Thank you that worked!!!
I would have never guessed that.

Has anyone made a list of inspector variables and there direct code equivalences?

Interesting notion, however I’ve never seen one such list before.

http://docs.unity3d.com/ScriptReference/ ?

After getting this TOO many times, it’s become my habit to add this to EVERY script.

using UnityEngine.UI;

Gigi

1 Like

that is great if your a hardcore coder, I can’t find : GetComponent<UnityEngine.UI.Image>().color
and I know what I’m looking for.

Unity has a (Open Reference for Image) but in the manual there is no code equivalency or a link to the ScriptReference page.

If you do what Gigi says, then you wouldn’t need two write the fully qualified name. Just GetComponent() would work fine.