That is, when you hold down a button, its function works until the user releases the button, can this be done?

    2 answers 2

    EventSystem (a class that is responsible for capturing input events and automatically added when the first Canvas is added) has a number of interfaces that allow you to track any actions related to it.

    For example, in your case you need two interfaces IPointerDownHandler and IPointerUpHandler . Inherit from them a class that hangs on the button and implement their methods.

    PointerDown triggered when the LMB is pressed over the object on which the script hangs. PointerUp - when the button was released.

    Also, I think you need to implement the IPointerExitHandler interface, its method is called when the cursor leaves the object. You will need this in order to disable the “clamping” if the player moves the cursor outside the button, while not releasing the clamped button.

      In the script, use the Update () {} function, and hang the script on the button.