【问题标题】:Unity new Input system not being triggeredUnity新的输入系统没有被触发
【发布时间】:2022-01-21 10:58:36
【问题描述】:

我遇到了一个奇怪的问题,即“根本”没有触发任何输入。 拔掉我的头发;找不到哪里错了。

结果是什么都没有被写入;虽然一切都已确定。 在输入资产中,我添加了“交互”和“应用程序退出”条目。

任何人都可以看到这里出了什么问题?

public class InputManager : MonoBehaviour
{
    [SerializeField] private InputActionAsset _actions;

    public InputActionAsset actions
    {
        get => _actions;
        set => _actions = value;
    }

    private InputAction quitInputAction { get; set; }
    private InputAction interactInputAction { get; set; }

    private void OnEnable()
    {
        quitInputAction?.Enable();
        interactInputAction?.Enable();
        Setup();
    }

    private void Setup()
    {

        interactInputAction = actions.FindAction("Interact");
        if (interactInputAction != null)
        {
            interactInputAction.started += OnInteract;
            interactInputAction.performed += OnInteract;
            interactInputAction.canceled += OnInteract;
        }
        else
        {
            Debug.LogError("Missing Interact Binding");
        }

        quitInputAction = actions.FindAction("Application Quit");
        if (quitInputAction != null)
        {
            quitInputAction.started += OnAppQuit;
            quitInputAction.performed += OnAppQuit;
            quitInputAction.canceled += OnAppQuit;
        }
        else
        {
            Debug.LogError("Missing Application Quit Binding");
        }
    }

    protected virtual void OnAppQuit(InputAction.CallbackContext context)
    {
        if (context.started || context.performed)
        {
            Debug.Log("Quit");
            Application.Quit();
        }

        else if (context.canceled)
            Debug.Log("Application Quit Cancelled");
    }

    protected virtual void OnInteract(InputAction.CallbackContext context)
    {
        if (context.started || context.performed)
        {
            Debug.Log("Interact");

        }

        else if (context.canceled)
            Debug.Log("Application Quit Cancelled");
    }
}

【问题讨论】:

  • 您使用的是什么输入资产?控制台中的任何错误?您的设置是否成功并且您的脚本日志显示出来了?

标签: c# unity3d input


【解决方案1】:

您是否按照分步教程创建操作映射? 您是否查看过 Unity Input Debugger 以查看您的输入是否使用了映射?一定要关注视频,因为阅读统一文档和屏幕截图不一定能让您正确了解如何设置它,而且很容易错过一些东西。

https://www.youtube.com/watch?v=YHC-6I_LSos

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    • 2020-12-27
    • 2022-01-14
    • 1970-01-01
    • 2020-12-31
    • 2022-07-06
    • 2022-07-20
    相关资源
    最近更新 更多