- Home /
How do I invert an input axis using Javascript?
I would like to create a boolean option for selecting whether the axis for MouseX and MouseY is inverted or not. I can obviously change this from within the Input Manager, but I would like to do this using the Unity GUI. I couldn't find anything in the scripting references.
Any help would be greatly appreciated.
Answer by duck · Mar 31, 2010 at 03:53 PM
Have a boolean variable which determines whether the input should be flipped. You can then simply multiply the Input value by -1 if the boolean value is true. Something like this:
var flipY = false;
function Update() { var inputY = Input.GetAxis("Vertical") * (flipY ? -1 : 1); }
You can then change "flipY" to true, and the inputY values will be reversed.
I have been looking at this example of yours and I think you are using the $$anonymous$$ouseLook.cs script in conjunction with this code right? Now I understand your piece of code here. It make's perfect sense to me but how to I use this to access the other script. I mean I know that $$anonymous$$ouseLook.cs will have to be on the same GameObject which is acting on but how do I connect the two via code.
I'm a little perplexed here too. The mouselook.cs script does not seem to like 'var' in the unity script sense. How do we make the two scripts interact?
Your answer
![](https://koobas.hobune.stream/wayback/20220612140431im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
FPC Mouselook Axis problem on pause GUI 1 Answer
Toggle the Y axis Invert in MouseLook.cs with a keystroke? 3 Answers
Disable Mouse Input when OnGUI() 1 Answer
Ensuring Correct Call Order 0 Answers
Press Keyboard Instead Of Mouse 2 Answers