Search Unity

Question How do I replace hardcoded keybinds to read off of the Input Action Map?

Discussion in 'Input System' started by DocPotter, May 18, 2023.

  1. DocPotter

    DocPotter

    Joined:
    May 6, 2023
    Posts:
    1
    Hi,

    I'm trying to create a Key re-binding system in Unity and using a Movement script created by Dani.

    I have the key-rebinding system already created and working, but I need the PlayerMovement script to read the Input Action Asset. I have a 2D Vector for Up,Down,Left,Right movement, an action for Jump and Crouch.


    This is the code that handles input:


    Code (CSharp):
    1.  private void MyInput()
    2.     {
    3.         x = Input.GetAxisRaw("Horizontal");
    4.         y = Input.GetAxisRaw("Vertical");
    5.         jumping = Input.GetButton("Jump");
    6.         crouching = Input.GetKey(KeyCode.LeftControl);
    7.  
    8.         //Crouching
    9.         if (Input.GetKeyDown(KeyCode.LeftControl))
    10.             StartCrouch();
    11.         if (Input.GetKeyUp(KeyCode.LeftControl))
    12.             StopCrouch();
    13.     }
    I want to replace the current way of handling input and put something to read the keybinds set in the Action Map without having anything hardcoded and I can't figure out how to.

    Any help would be much appreciated.

    Thanks