Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Invert vertical axis in inputmanager through script

Discussion in 'Scripting' started by boooels, Nov 11, 2018 at 12:38 AM.

  1. boooels

    boooels

    Joined:
    Oct 26, 2018
    Posts:
    15
    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:
    53
    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:
    15
    Thank you so very much! Works like a charm!
     
  4. santiagolopezpereyra

    santiagolopezpereyra

    Joined:
    Feb 21, 2018
    Posts:
    53