人物系统构建1
移动
利用更灵活便于扩展的InputSystem 代替原生的InputManager.
InputSystem 使用
- 右键菜单->Create->InputSystem.
- 设置用户输入
3.脚本中用委托的形式接受
private void OnEnable()
{
if (inputActions == null)
{
inputActions = new PlayerControllers();
inputActions.PlayerMovement.MovementAction.performed += data =>
movementInput = data.ReadValue<Vector2>();
}
inputActions.Enable();
}
4.单帧去赋值给坐标,接受的变量类型取决于,Action红色框中定义的变量(这里用刚体的vecolity属性,直接改transform.positon也可以)
private void Update()
{
Vector3 vector3 = new Vector3(movementInput.x * movementSpeed,0,movementInput.y*movementSpeed);
Debug.Log(vector3);
rigidbody.velocity = vector3;
}