disable getMouseButtonDown when click when click a button
hey i want to ask something, im a beginner in unity and sorry for my bed english. i have a script input get mouse button like this
if (Input.GetMouseButtonDown (0)) {
//Debug.Log("klik");
handleInteraction (true);
}
and when i click a mouse, player will jump. i have a pause button to. i want when i click a pause button, function of get mouse button down disable or not work. (my problem is because when i click a pause button a player still jumping and then game paused). thxu
Answer by Mmmpies · Jun 13, 2016 at 08:40 AM
You could add a couple of functions to alter the state of a bool call it something obvious like CanMouseJump.
public void MouseJumpOn()
{
CanMouseJump = true;
}
public void MouseJumpOff()
{
CanMouseJump = false;
}
Add An Event Trigger to the Pause button and add 2 events, one for On Pointer Enter and one for On Pointer Exit. Drag whatever has that script onto the slot and from the drop down select YourScriptName -> MouseJumpOff for On Pointer Enter and MouseJumpOn for On Pointer Exit.
Finally edit that jump check.
if (Input.GetMouseButtonDown (0) && CanMouseJump) {
So if you're over the Pause button the mouse jump is off.
Generally it's not a good idea mixing Mouse Button Down and UI input but for 1 button it's not too much of an issue.
Answer by unity_g_5opRbYMjtxxQ · Dec 17, 2020 at 12:39 PM
You can use if (Input.GetMouseButtonDown (0) && !EventSystem.current.IsPointerOverGameObject()) { //Code goes here }