导入包
这里点击
no
一会自行设置
设置新版输入系统
这里我选择了同时兼容新旧输入系统
创建 Input Actions
编辑 Input Actions
生成脚本
在气体脚本中使用
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
private PlayerControlls controls;
private void Awake()
{
controls = new PlayerControlls();
controls.Character.Fire.performed += ctx => Shoot();
controls.Character.Movement.performed += ctx => Movement(ctx.ReadValue<Vector2>());
}
private void OnEnable()
{
controls.Enable();
}
private void OnDisable()
{
controls.Disable();
}
/// <summary>
/// 射击
/// </summary>
private void Shoot()
{
Debug.Log("Shoot");
}
/// <summary>
/// 移动
/// </summary>
/// <param name="direction"></param>
private void Movement(Vector2 direction)
{
Debug.Log("Move: " + direction);
}
}
已有 0 条评论