首页 > 解决方案 > 新的输入系统不发送消息?

问题描述

我正在使用 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 时我错过了什么?

标签: unity3d

解决方案


我必须在我的控制方案中将键盘和鼠标添加到表格中Edit Control Scheme...

Unity 控制方案编辑器截图


推荐阅读