我正在使用 Unity 的输入系统,并根据控制方案定义了我的控件(
)
我的播放器上有播放器输入组件,还有我的角色输入,用于处理播放器输入。我想实现 SendMessages 形式的输入,所以这是配置:
最后,我在同一个对象上有我的 CharacterInput 类,代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(Rigidbody2D))]
public class CharacterInput : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
}
public void OnMove(InputValue input)
{
Debug.Log("aha");
Vector2 inputVec = input.Get<Vector2>();
HandleMove(inputVec);
}
private void HandleMove(Vector2 fromInupt)
{
transform.position += new Vector3(fromInupt.x * speed * Time.deltaTime, 0, fromInupt.y * speed * Time.deltaTime);
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是WASD的输入不输出调试消息。所以我的问题是,在让 PlayerInput 调用 OnMove 时我错过了什么?