首页 > 解决方案 > 命名空间“UnityEngine.Experimental”中不存在类型或命名空间名称“Input”

问题描述

我正在使用统一的新输入系统并收到此错误,我尝试了很多来修复它但找不到问题。请帮我。

错误:

Assets\Player01.cs(4,32): error CS0234: The type or namespace name 'Input' does not exist in the namespace 'UnityEngine.Experimental' (are you missing an assembly reference?)

完整脚本(C#):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Input;

public class Player01 : MonoBehaviour
{
    public InputMaster controls;

    void Awake ()
    {
        controls.Player01.Shoot.performed += _ => Shoot();
    }

    void Shoot ()
    {
        Debug.Log("We shot the sherif!");
    }
    
    private void OnEnable()
    {
        controls.Enable();
    }
    private void OnDisable()
    {
        controls.Disable();
    }
}

标签: c#unity3d

解决方案


问题是没有UnityEngine.Experimental.Input. 但是,它只说“‘输入’在命名空间‘UnityEngine.Experimental’中不存在”。“实验”确实存在,“输入”不存在。但是,“输入系统”可以。那就是您要寻找的那个,而不是“输入”。您应该将第一行更改为:


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

public class Player01 : MonoBehaviour
...

推荐阅读