繁体   English   中英

导入 UnityEngine.InputSystem 的问题。 找不到错误 CS0246 类型或命名空间

[英]issue importing UnityEngine.InputSystem. Error CS0246 type or namespace not found

尽管完全复制了教程的代码,但我无法运行我的代码。

这是视频。 代码可见11:37。

我在 2 或 3 天前安装了 unity,所以我怀疑这是一个更新问题(我在另一个线程上看到有人这么说)

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

public class controle : MonoBehaviour
{
private PlayerControls controls;  // the error points at this line, at whatever position the "PlayerControls" string is

private void Awake()
{
    controls = new PlayerControls();
    controls.Gameplay.Forward.performed += Forward;
}


void Forward()
{
    transform.position.z -= 1.1 * f;

}

void OnEnable()
{
    controls.Gameplay.Enable();
}

void OnDisable()
{
    controls.Gameplay.Disable();

}


}

这可能是因为编译器顺序问题; 您的控件controle可能在PlayerControls存在之前编译,因此它无法访问它。
这是一个例子
检查您是否将文件放在标准资产文件夹中,因为那里的文件是在所有其他 class 脚本之前编译的。
你可以在这里阅读更多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM