首页 > 解决方案 > Unity 如何在脚本 CS0246 中正确声明输入操作

问题描述

我正在关注在 Unity 中编写输入操作脚本的教程

在完成教程告诉我的编码后,我在输入系统的东西的声明中遇到了这个错误CS0246 The type or namespace name 'InputActions' could not be found

导致错误的代码是:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class GameInput : MonoBehaviour
{
    private InputActions InputActions;
    private InputAction StartAction;
    void Start() {
        InputActions = new InputActions();
        }
    private void OnEnable() {
        StartAction = InputActions.Start.Start;
        StartAction.Enable();

        InputActions.Start.Start.performed += StartGame;
        InputActions.Start.Start.Enable();
    }
    public void StartGame(InputValue value) {
        // CODE HERE
    }
}

该错误是由声明引起的,我认为它是由可能不存在private InputActions InputActions; 的变量类型引起的。InputActions但是本教程还使用了一种不存在的类型。

如何让 Unity 识别 InputActions 类型?

标签: c#unity3d

解决方案


Typo:Unity没有InputActionsType,但是有InputActionType。看看您在示例中如何拼写不同的类型。InputActions不存在所以你不能使用它。

更改InputActionsInputAction


推荐阅读