Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Get position for the "Click" event?

Discussion in 'Input System' started by mortoray, Aug 4, 2023.

  1. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    89
    How do I properly get the position where an interface click event occurred?

    That is, in an InputActionMap I have the standard "Click" event as below.
    upload_2023-8-4_9-32-26.png

    I add a performed listener, but then want to know where it occurred. Right now I'm reading the current mouse position, which isn't correct since it might not be a mouse (could be pen/finger/other).
    ```
    void OnClicked(InputAction.CallbackContext context) {
    var position = Mouse.current.position.ReadValue();
    ```

    What's the right way to get the position at the time the "Click" action happened?
     
    DevDunk likes this.
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,175
  3. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    89
    Yes, that'll appear to work. What I did now is to listen for `Point` input action as well, which is mapped from all the devices. I just store it in a variable as it happens.

    The ReadValue on a button action, like Click, is a float value about how much the button is pressed. For a mouse button this is either 0 or 1.
     
    DevDunk likes this.