Simultaneous button and function

There are two scripts one has the on click event of the button

public void ActivatePausedMenu()
{
pauseMenuActive = false;
StopAllCoroutines();
StartCoroutine(PauseMenuCoroutine());
}

and the other has the general functionality which references the boolean in the other script

if(!coreFunctionality.pauseMenuActive)
{
if (Input.GetMouseButtonDown(0))
{
//does stuff
}
}

it does work but it takes a second, so this ends up with the function always activating when the button is pressed

Is there a way to stop general functionality of a click or tap when pressing a button?

First of all, when you post code, Please use code tags: https://discussions.unity.com/t/481379

Without seeing any more, I speculate that the delay is within the PauseMenuCoroutine() coroutine.

Set the button’s .interactable property to false and it will stop responding to clicks.

https://docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.Selectable-interactable.html

Thanks for the reply and sorry about not using the code tags, I will use them in future

I’ve tried activating it with a function that doesn’t have the coroutine, it doesn’t make a difference

I was talking about making all clicks or taps from code like

Input.GetKey(KeyCode.Mouse0)

Input.GetMouseButtonDown(0)

not work so that while the button is tapped or clicked everything else that has a click or tap stops working

You can just make your own boolean:

private bool ClicksEnabled = true;

and turn it off when you don’t want that input.

Then just check it before you do your input check:

if (ClicksEnabled)
{
  if (Input.GetMouseButtonDown(0))
  {
  }
}

Alternately you can still accept the raw intent of the click, but then where you process the intent check that variable. It sorta depends how you have stuff organized.

That’s pretty much what I did

It sounds like your telling me normally this is completely possible?

Oh well, maybe I’ll try having the boolean in the same script. It could be that referencing another script creates the delay for the input to assume the condition hasn’t been met for a few milliseconds

It certainly is. Just understand the parts and what they mean in your setup:

  1. you know when you don’t want to hear from the mouse (and when you do)
  2. you know where you check the mouse intent
  3. you know where you act on the mouse
  4. therefore make something that communicates the “I want to hear from you” status to somewhere to interrupt the processing of the mouse intent.
1 Like

Thank you very much for the help

Definitely will use these as a reference

I think it might be to do with the call stack in Unity? The boolean is constantly checking for input in update, so maybe the button click or tap might be only registered after update?

It’s currently a polish bug at the end of a whole bunch of other things, but if you’re still around when it does get fixed or if I’m still stuck I’ll post it here. Thanks again for the replies and help, it’s very much appreciated