Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

is there an easy way to emulate the Input.GetAxis("Horizontal") in the new input system ?

Discussion in 'Input System' started by nasos_333, Apr 21, 2021.

  1. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,914
    Hi,

    I try to replace the Input.GetAxis("Horizontal") with the new input system

    in my code and cannot seem to find an easy way around it, it requires some external behavior which increases the complexity of my system exponentially.

    Is there a way to do it only with script, without modify anything in my project scene or add any extra scripts ? Just a code replacement in place of the Input.GetAxis("Horizontal").

    And perhaps grab the reference of the buttons from old declarations, so no new info may be needed outside few lines of code ?

    Thanks a lot
     
    Last edited: Apr 21, 2021
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,923
    AFAIK there is no 1:1 replacement to the old virtual controls in the new system. Only have the concrete implementation of devices like Mouse or Keyboard, etc.
    The best you can do is create actions in code instead of in assets or components.
    https://docs.unity3d.com/Packages/c.../manual/Actions.html#creating-actions-in-code
     
    Last edited: Apr 21, 2021
    nasos_333 likes this.
  3. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,914
    Thanks a lot will check i out, if is pure code i dont mind even if complex, i just not want to alter my scene.
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,923
    No problem, you can do everything in code in the new input system, so I think you'll be fine. :)
     
    nasos_333 likes this.
  5. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,914
    I checked the link, this is great :), thanks a lot :), is exactly what i was looking for
     
    Lurking-Ninja likes this.
  6. juaojones

    juaojones

    Joined:
    Oct 5, 2020
    Posts:
    1
    I know is a bit late, but for anyone who want this in the future.

    You can call the input on a Method:
     public void OnMovement(InputAction.Callback value)
    {
    //Declare this Vector 2 before this, so you can use it in other methods and just the implement the value here
    Vecto2 inputMovement = value.ReadValue<Vector2>();

    }

    //now you can call the horaizontal like this:

    public void Move()
    {

    float inputHorizontal = inputMovement.x;

    }

     
    nasos_333 likes this.
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,914
    Great, thanks :)