c# - 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 类型?
解决方案
Typo:Unity没有InputActions
Type,但是有InputAction
Type。看看您在示例中如何拼写不同的类型。InputActions
不存在所以你不能使用它。
更改InputActions
为InputAction
。
推荐阅读
- c# - ComboBox 的 SelectedItem 的变化改变了 ItemsSource
- kotlin - 为泛型类型添加静态扩展
- logging - 检测到 Logback 配置错误
- nginx - 无法选择合适的插件:nginx 插件不起作用;
- time-complexity - 检查二叉树是否为 avl 树的最佳时间复杂度(高度平衡)
- java - 如何在 Java 中复制 Swing 组件及其属性?
- python - 在 tensorflow 中读取 LZO 压缩的 csv 文件
- windows-ce - 我们如何在 Windows 10 中创建 Wince 6.0 设置?
- reporting-services - 将来自不同域林的用户添加到 SSRS 时遇到问题
- python - 从 Facebook 导入事件的问题