How to know if a button is clicked, not only when it starts

Is there a variable in buttons saying if its (not only when it starts) being clicked?

thanks

Get Key Up only fires when the user stops pressing the key. If that helps. Not sure what you’re asking otherwise

KeyCode mouseClickL = KeyCode.Mouse0;
Input.GetKeyUp(Options.mouseClickR)
  1. I said always, not just at the end
  2. I was referring to UI Buttons

I don’t know what you’re asking. Sorry.

Is there a variable in UI buttons that tells you if the button is being pressed? Not only if the press started or ended.

Did you added Button in Inspector > add component > button

Now in play when you click said item it will show you Pressed visual But nothing will happen further than that unless you use code

My question is how do i do that code you said at the end of the sentence?

Is there a variable in UI buttons that tells you if the button is being pressed? Not only if the press started or ended.

Not unless you can see it in here. Sorry. I think it just fires on click. You would have to script something using an IClickHandler.

What’s an IClickHandler?

I suggest watching some button functionality related videos on youtube . You need code to work for functionality . And attach that code to button
here
Buttons

Basically, it’s a way to tell a Unity script you would like it to listen for mouse clicks and then do something about it. My recommendation is to:

  1. Use OnPointerEnter to sense when the pointer is in the button box by activating a bool.
  2. Use OnPointerExit to sense when it’s not there, and deactivate.
  3. Use Update to check when the mouse button is down.

Is that something you can work out do you think?

Is it like this?

    Button button;
    bool isClick;

    void Start()
    {
        button = GetComponent<Button>();
    }

    void OnPointerEnter()
    {
        isClick = true;
    }

    void OnPointerExit()
    {
        isClick = false;
    }

    void Update()
    {
        if (Input.GetMouseButton(0) && isClick)
        {
            //do things
        }
    }
1 Like

Is it like that??

YAY I GOT IT TO WORK

thanks to that video

1 Like

That’s really good work. :slight_smile: I’m glad you managed to do it, and I hope it helps your game.