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?
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.
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”
}
}