Unity new input system

1. Import new input system

(1)

 Change it to .NET Framework here, and change it to input system package (New) below.

2. Use the new system

(1)

Add the Player Input component to your player object and then CreateAction

(2)

Create this file

 

Click it and check the right window to generate a corresponding class. You can call this class to perform operations in the future.

 

 (3) How PlayerController code uses the new system

using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public PlayerInputControl inputControl;

    public Vector2 inputDirection;
    private void Awake()
    {
        inputControl = new PlayerInputControl();
    }

    private void OnEnable()
    {
        inputControl.Enable();
    }
    private void OnDisable()
    {
        inputControl.Disable();
    }
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        inputDirection = inputControl.Gameplay.Move.ReadValue<Vector2>();
    }
}

When you run the game at this time, you can find the input key values ​​that have been read out.

Guess you like

Origin blog.csdn.net/holens01/article/details/131502243