简体   繁体   中英

how to fix 'The type or namespace name 'PlayerManager' could not be found (are you missing a using directive or an assembly reference?

í am trying to access the playermanager from ThirdPersonUserControl but it is not working and giving ther error

I have tried referencing but still no good

class 1

public class PlayerManager : MonoBehaviour{}

class 2

public PlayerManager manager;

    private void Start()
    {

        manager = gameObject.GetComponent<PlayerManager>();
    }

It is hard to tell with so little information. Ideally a compilable piece of code that people can drop into a blank project.

Do both classes/files use the same namespace? To use classes in another namespace, the file must contain a "using directive", eg using System; or you must use the complete name, eg System.Console.Write("Test"); for the Console class in the System namespace.

Are they both in the same project? Classes in different projects, or external DLLs will also need an assembly reference, in Visual Studio you can see these in the "Solution Explorer", if you expand your project and then "References", which will be at the top of the project.

Usually with Visual Studio (or other IDEs) for things like this it will underline the error in red, and can provide some hints on how to also fix it. In the case of Visual Studio, right click "Quick Actions and Refactorings..." or with the default shortcut Ctrl + . it may offer to add an using directive or an assembly reference for you automatically.

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