Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Old Input System (GetAxis("Horizontal")) to New Input System?

Discussion in 'Input System' started by Duckduckguz, Nov 23, 2023.

  1. Duckduckguz

    Duckduckguz

    Joined:
    Jun 26, 2022
    Posts:
    4
    I'm having trouble transferring my code into the new input system. I've searched and searched, but for some reason, I don't know how to make this code:

    Code (CSharp):
    1.         // physical movement
    2.         var movement = Input.GetAxis("Horizontal");
    3.         transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
    4.         animator.SetFloat("MovementSpeed", Mathf.Abs(movement));
    5.  
    6.         // rotation based on movement direction
    7.         if (movement > 0)
    8.         {
    9.             transform.rotation = Quaternion.Euler(0, 90, 0);
    10.         }
    11.         if (movement < 0)
    12.         {
    13.             transform.rotation = Quaternion.Euler(0, 270, 0);
    14.         }
    15.  
    into the new input system. I already have it set up in the Input Manager, but I don't know how to do this! Can someone please help me? Thanks, y'all.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,279