Unity新输入系统

1、导入新输入系统

(1)

 这里改成.NET Framework,下面改成input system package(New)

2、使用新系统

(1)

在你的player物体上添加Player Input组件,然后CreateAction

(2)

创建出这个文件

 

点击它,在右侧窗口上打钩,生成一个对应的类,以后可以调用这个类来进行操作

 

 (3)PlayerController代码如何使用新系统

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>();
    }
}

此时运行游戏可以发现已经读出的输入的按键值

猜你喜欢

转载自blog.csdn.net/holens01/article/details/131502243
今日推荐