how do i change the color of GUI Button when clicked on thst particular button.
can anyone help with C# code…
Thanks for your answer in Advance
how do i change the color of GUI Button when clicked on thst particular button.
can anyone help with C# code…
Thanks for your answer in Advance
Ok I removed the old answer since I realized I was going nowhere. Now this one is tried and working:
bool blue;
void Start(){
blue =true;}
void OnGUI() {
if(blue)
GUI.color = Color.blue;
else
GUI.color = Color.yellow;
if(GUI.Button(new Rect(100,110,70,30), "A button"))
blue= !blue;
}
I did it with Js and translate it to c# here so you might want to check twice the syntax as I am not using c# and am not confident with it…
original Js version
var blue:boolean = true;
function OnGUI() {
if(blue)
GUI.color = Color.blue;
else
GUI.color = Color.yellow;
if(GUI.Button(Rect(100,110,70,30), "A button"))
blue= !blue;
}
You have to assign a GUIStyle to the button and replace the background image.
var gStyle : GUIStyle;
var blueTex : Texture;
var redTex : Texture;
function Start() {
gStyle.normal.background = blueTex
}
function OnGUI() {
if(GUI.Button(Rect(0, 0, 100, 100), "Change Color" gStyle))
gStyle.normal.background = redTex
}