- Home /
Question by
itsboshytime · Mar 08, 2014 at 12:37 PM ·
c#guiguitexturetoggleguibutton
Toggle GuiTexture
Hello,
I have been working an an mute/unmute button in the game. The problem is that it does not toggle correctly when pressed. When i press it apparenty it gets togggled both on and off at the same time, leaving the same texture. I have 2 textures for the button, but only the on one appears.
Rect position = new Rect(native_width-175,90,125,125);
GUI.DrawTexture(position , musicTextureToggle);
if (GUI.Button(position , "", new GUIStyle()))
{
if (musicOn==1)
{
musicTextureToggle = musicTextureOff;
musicOn = 0;
PlayerPrefs.SetInt("isMusic",musicOn);
Debug.Log("mute");
}
if (musicOn==0)
{
musicTextureToggle = musicTexture;
musicOn = 1;
PlayerPrefs.SetInt("isMusic",musicOn);
Debug.Log("unmute");
}
}
Comment
Best Answer
Answer by RudyTheDev · Mar 08, 2014 at 12:38 PM
You need an else
before second if (musicOn==0)
or it simply undoes what the first if (musicOn==1)
did.