How to get index of current mouse button down

Thanks for the great info and the straightforward explanation,
I am using 2 mouse buttons left and the right one for selecting and one for deselecting, My question is: how to get the index of Which mouse button is pressed, I don’t want to add two keybindings I am sure there is a way to the get the index, like in the old input system: Input.GetMouseButtonDown(button) I just want to know how to get the index
I have used “Press [Mouse]” for the binding, is that correct, or how to do this?
Thank you very much

Here are your 3 mouse buttons.

Thank you but that’s not what I am looking for,
I am looking for how to get the index (0,1,2) using the new input system not the old one
and using one method I don’t want to do any checks ,keep it clean as possible

Not sure about the index, per se, but you can check
Mouse.current.leftButton and Mouse.current.rightButton etc

Unity New Input System - Mouse Support

Edit: you receive a CallbackContext which may hold more info. I’m not sure

Thank but that’s not close to what I want
I am still searching, I think it’s not accessible like in the old input system

Can you show us a picture of this new input system, like a screen shot or something?

here is a full video about it

Okay, I’m sure it’s in there somewhere then. Sounds like you found your answer.

No actually I haven’t yet

I can see what you are trying to do, but the new input system don’t exactly work like the old one anymore. If you want to do it like you said (and I see you tagged the turn-based strategy game), you would need to add more actions

and then update your InputManager script to do that

// truncated InputManager.cs
    public bool IsMouseButtonDownThisFrame(int button)
    {
#if USE_NEW_INPUT_SYSTEM
        switch (button)
        {
            case 0: return _playerInputActions.Player.Select.WasPressedThisFrame();
            case 1: return _playerInputActions.Player.Deselect.WasPressedThisFrame();
            default: return false;
        }
#else
        return Input.GetMouseButtonDown(button);
#endif
    }

With this, you can use it in the same way as before, like


for(int button = 0; button < 2; button++)
{
    if (InputManager.instance.IsMouseButtonDownThisFrame(button))
    {
        Debug.Log($"Button {button} was pressed");
    }
}

Edit: I have not used the new input system very much, so this is the best guess I have based on what we did in the course, and the knowledge I have of how it works. I also know you said you don’t want to create more bindings, but I’m not sure how else you will achieve what you want

3 Likes

What is the significance of using the ‘New Input System’? Are you creating something for mobile with an option to port it to a PC?

What is wrong with the regular input system that causes you to not want to use it?

Your posts suggest that you’re looking for something like this:

MouseInput

…but in your responses you said specifically this is absolutely not what you want.

I’m not sure how to help you.

1 Like

That’s exactly what I wanted ,Thank you very much
My approach was wrong , I thought I would be able to get “AnyMouseButtonDown” and get the index of the button pressed , but like you said the new input system doesn’t work that way “I guess” , thank you so much for your effort

1 Like

Hi Jay
I don’t know how gamedev work , but I asked this question on a video from the turn based game course , the video is showing how to use the new input system , and I wanted to expand a bit on it
Thanks for trying to help I appreciate it

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms