x


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.

more ▼

asked Mar 31 '10 at 03:43 PM

ocard gravatar image

ocard
54 2 2 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 31 '10 at 03:53 PM

duck gravatar image

duck ♦♦
40.9k 92 148 415

I have been looking at this example of yours and I think you are using the MouseLook.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 MouseLook.cs will have to be on the same GameObject which is acting on but how do I connect the two via code.

Dec 03 '10 at 04:36 PM mimatos

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?

Jan 08 '11 at 08:38 PM phosfiend
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3668
x981
x321
x19

asked: Mar 31 '10 at 03:43 PM

Seen: 2006 times

Last Updated: Mar 31 '10 at 03:43 PM