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. Dismiss Notice

Actions Left Mouse Button DOWN notification

Discussion in 'Input System' started by Mike99, Mar 11, 2020.

  1. Mike99

    Mike99

    Joined:
    Dec 11, 2011
    Posts:
    160
    Hi,

    I've set up an action called 'Fire' for the left mouse button, but when I log the event callback, I get three messages instead of one. I suppose it's because I get down, hold and up events.

    How do I specify to get only the down for instance ?

    Thanks,
     
  2. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Actually, what you're getting is probably started, performed, and canceled events.

    There is multiple ways you can do that :

    1. On your action, add a press interaction set to Press only

    2. On your callback, use this :

    Code (CSharp):
    1. public void YourCallBack(CallbackContext ctx)
    2. {
    3.     if(!ctx.performed) return;
    4.  
    5.     // your logic
    6. }
     
  3. Mike99

    Mike99

    Joined:
    Dec 11, 2011
    Posts:
    160
    yep, thanks,

    I ended using ReadValue function.

    What I didn't get is that I need to generate the c# class from the actions to then access everything.

    TY
     
  4. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    You don't NEED to, you can. You can either use the PlayerInput component, and bind your callbacks in here. You can use InputActionReferences, or you can use the generated C#. It all depends to you / what you prefer