- Home /
Question by
TheFacelessOne · Sep 07, 2014 at 06:26 PM ·
uibutton
Changing UI Buttons color
I'm trying to make a button change color depending on an array. If hand[0]=='f', color==red. And so on for the other 13 cases. I'm trying to get a script that checks if anything other than '_' is in the spot, and if so, color=changed. How can I do that? There is no UI.button.image.color setting.
Comment
Answer by Umai · Dec 29, 2014 at 01:06 AM
You can do this, it will change the colors of a button. This will give the button a half transparent red background.
ColorBlock colorblock = ColorBlock.defaultColorBlock;
colorblock.normalColor = new Color(1, 0, 0, 0.5f);
somegameobject.GetComponent<Button>().colors = colorblock;
Answer by shriya · Dec 29, 2014 at 06:24 AM
hi,
I guess you are missing a library which is required to access new UI elements.
using UnityEngine.UI;
I hope it helps.
its about accessing the colors
variable and not the UI button
.
Answer by MEFASTO · May 30, 2016 at 05:20 AM
public UnityEngine.UI.Button ButtonProxCena;
ButtonProxCena.GetComponent<UnityEngine.UI.Image>().color = Color.black;