- Home /
OnGUI Button doesn't execute until I release the button
I have this inside my OnGUI function
if (GUI.Button (Rect (side, height, side, height), "", jumpbutton)) {
jump=true;
}
and then I have an update function which moves a character controller and if jump is set to true the character controller jumps. The GUI button doesn't send the jump = true message until the button is released is their anyway to send this signal as soon as the button is pressed? I've tried messing around with the GUI.RepeatButton and tried to just detect the first instance of setting jump to true and then ignoring the rest but it's gonna be a bit of a hassle to redo my code.
Is there a better way to immediately detect the button press?
Answer by maddFrogg · Apr 24, 2014 at 12:15 PM
Write this in Update method
if ( Input.GetMouseButtonDown( 0 ) ) {
jump = true;
}
You will need to detect if the click position is correct in order to jump. If not, every screen click will make the object (or whatever) jump.
Ah, I didn't realise there was a way to add bounds to that. I was using that before but wanted to add multiple functionalities to multiple buttons. That's great, thanks.