Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Doghelmer · Feb 07, 2017 at 07:05 AM · mousemouseclick

Way to swap left and right mouse buttons?

Is there a simple, easy way to get Unity to recognize the left mouse button as the right mouse button, and vice versa, without doing a bunch of modifications to my code?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Feb 07, 2017 at 07:55 AM 0
Share

whenever you use Get$$anonymous$$ouseButton/Up/Down, the parameter is the mouse button. 0 is left and 1 is right (I think). just use them vice versa

avatar image Doghelmer hexagonius · Feb 07, 2017 at 08:05 AM 0
Share

This is the sort of thing I'm trying to avoid. There are other cases (such as clicking buttons) that would require different solutions. I want to offer my users the option to swap mouse buttons if they'd prefer because someone requested it, but it would be more effort than it's worth if there's not a solution that wouldn't require me to go through my code and change a bunch of stuff.

avatar image aFeesh · Feb 07, 2017 at 09:58 PM 0
Share

How are you handling input? There is a very easy way if you are using the Input$$anonymous$$anager that Unity provides. Located under Edit >> Project Settings >> Input

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SvendErik · Feb 08, 2017 at 04:06 PM

If you use the premade input, Input.GetButton("Fire1") for example, then just change it either everywhere in the code (shift the 1 with 2 after Fire, for example). Or you can do it in the editor, so that every script will have them swapped. You can do it via edit - project settings - input. I do not recommend that, however. It can be very confusing.

But if you used Input.GetKey instead, then you pretty much just have to change it manually everywhere. You could maybe even make it a setting in your game. You could have a UI button, which calls a method, that changes all your Keycode variables to what you want. You can make a keycode variable like this: public KeyCode myKey = KeyCode.LeftArrow; You can then use it like this

Update() { if (Input.GetKey(myKey)) { MoveLeft(); } }

And change it like this:

myKey = KeyCode.RightArrow;

I've most likely written a lot you already know, but it might help some others to. Feel free to tag me with a question, if you want me to explain something of this a little better.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by SvendErik · Feb 08, 2017 at 08:59 AM

I suppose you're using Input.GetButtonDown("Fire1")) and Fire2. You can make this into variables.

Public string leftMouse = "Fire1" Public string rightMouse = "Fire2" Book swapped = false;

You can then use the variable when checking input

if (Input.GetButtonDown(leftMouse)) { // Do whatever you want with the left click }

And the same just with rightMouse You can now make a UI button, which calls this method

Public void SwapButtons () { if (swapped == false) { leftMouse = "Fire2" rightMouse = "Fire1" } else { leftMouse = "Fire1" rightMouse = "Fire2" } }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect mouse clicks anywhere on the screen except given gameobject 2 Answers

"Working with moving and mouse touch to set coordinates" 0 Answers

Mouse movement and click effect 1 Answer

Input.GetMouseButtonDown not working on WebGL build 2 Answers

Unity sometimes misses Mouse Button Release 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges