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

> NullReferenceException: Object > reference not set to an instance of an > object werda.Update () (at > Assets/dart/werda.cs:34) > > -==== checking word: vgbgfbgbgb UnityEngine.Debug:Log(Object) > werda:Update() (at > Assets/dart/werda.cs:32) I have no idea how this is even possible, it's almost like Start() is not called at all. Can you upload the textfile anywhere so i can test this with "real" data? You can also email it to me at trogmaniac@gmail.com

2 Answers

2

You can use
if (Input.GetMouseButtonDown (0) && !EventSystem.current.IsPointerOverGameObject())
{
//Code goes here
}

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.