- Home /
Question by
Kensei · Aug 05, 2014 at 05:22 PM ·
c#pauseboolaudiolistener
Why does this bool get reset?
if(GUI.Button (new Rect (860,600, 20,75),"Mute(M)","button") || Input.GetKeyDown("m"))
{
AudioListener.pause = !AudioListener.pause;
print (AudioListener.pause);
}
I don't understand. In the console it goes False and then True in the same frame. What am I missing? I press the key only once, not like I'm doing it every frame.
Comment
Best Answer
Answer by tanoshimi · Aug 05, 2014 at 05:32 PM
OnGUI (which I'm assuming is the function containing this code) is called multiple times per frame, and for that reason shouldn't contain any game logic - only GUI code.
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html
Ah ballz, thanks man. Can't describe how many times I dogged myself out in writing game logic in ongui -.-
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Bool wont change... #C 1 Answer
Pause movement on collision 2 Answers
Make enemy wait before attacking player 2 Answers