Search Unity

Invert vertical axis in inputmanager through script

Discussion in 'Scripting' started by boooels, Nov 11, 2018.

  1. boooels

    boooels

    Joined:
    Oct 26, 2018
    Posts:
    31
    as the title says im looking for a way to access the predefined "Vertical" axis in the input manager and invert them, so up becomes down and vice versa. I know theres a checkboc for that. But im wondering if i can access that via script so i can change it during runtime. Or at least something that works similar to that.
    Thanks for your time :)
     
  2. santiagolopezpereyra

    santiagolopezpereyra

    Joined:
    Feb 21, 2018
    Posts:
    91
    Very simple :)



    Code (CSharp):
    1. void Update () {
    2.   float invertedAxis -= Input.GetAxis("Vertical");
    3. }
    With the -= sign, you are saying that invertedAxis is equal to the negative value of the axis. So if axis is positive, it becomes negative; if it's negative, it becomes positive. :)
     
  3. boooels

    boooels

    Joined:
    Oct 26, 2018
    Posts:
    31
    Thank you so very much! Works like a charm!
     
  4. santiagolopezpereyra

    santiagolopezpereyra

    Joined:
    Feb 21, 2018
    Posts:
    91