Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

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:
    88
    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:
    88