unity3d - 新的输入系统不发送消息?
问题描述
我正在使用 Unity 的输入系统,并根据控制方案 ( )定义了我的控件
我的播放器和 CharacterInput 上有播放器输入组件来处理播放器输入。我想实现 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);
}
}
所以我的问题是 WASD 的输入没有输出调试信息。所以我的问题是,在让 PlayerInput 调用 OnMove 时我错过了什么?
解决方案
我必须在我的控制方案中将键盘和鼠标添加到表格中Edit Control Scheme...
推荐阅读
- html - Bootstrap navs,如何固定内容高度
- c++ - std::copy 导致运行时检查失败 #2
- android - Android:类不允许被夸大 android.widget.Switch
- machine-learning - 当所有逻辑都用另一种语言实现时,如何在 Python (sklearn) 中使用现成的 ML 模型?
- php - PHP 自定义函数与 as 语法,函数 ($x as $y)
- html - 我没有让汉堡菜单栏工作
- sql-server - 如何在 SQL Server 中的一次选择中编写多个联合选择
- neo4j - Neo4j 获取与节点列表相关的所有节点
- c# - 鼠标外观脚本中的 X 轴错误,但 y 轴正常吗?
- multithreading - 尝试在 2 个线程中运行 asio 时在 (ntdll.dll) 访问冲突读取位置引发异常