Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my 2nd mouse button not detecting unity (beginner)

I am trying to make a multiplayer fps game using photon and the ads is a big part. For some reason, the right mouse button is not registering, but every other one is. It works on my mouse outside of unity, but it does not work inside. My lmb is working for the ads, so I do not know why this is the case.
Here is the snippet for the aim;

 }
            if (Input.GetMouseButton(2))
            {
                animator.SetBool("rmb", true);
            }
            else
            {
                animator.SetBool("rmb", false);
            }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

GetMouseButton(2) is for the middle-click button (pushing down on the scroll wheel), not the right mouse button. Use GetMouseButton(1) instead:

Small tip, you can skip the if check entirely just by passing the result of Input.GetMouseButton directly to the "rmb" parameter of the animator:

animator.SetBool("rmb", Input.GetMouseButton(1));

Documentation: Scripting API: Input.GetMouseButton

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading