簡體   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