简体   繁体   中英

The type or namespace name 'Input' does not exist in the namespace 'UnityEngine.Experimental'

I am using unity's new input system and getting this error, I tried a lot to fix it but can't find the problem. Please help me.

Error:

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?)

Full Script(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();
    }
}

The problem is that there is no namespace of UnityEngine.Experimental.Input . But, it only says “'Input' does not exist in the namespace 'UnityEngine.Experimental'”. 'Experimental' does exist and 'Input' does not. However, 'InputSystem' does. And that is the one you are looking for, not 'Input'. You should change the first line to this:


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

public class Player01 : MonoBehaviour
...

Just in case, if the first solution did not work, Close vs studio / code if open, then go to Edit -> Project Settings -> Input System Manager. There will be only one option available. Click the button, save your scene. Open a script. This worked for me. A lot of tutorials do not mention this part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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