C# MapCamera: Singleton throws an error

In Unity3d, when creating the "public class MapCamera : Singleton" class, it throws an error: - The namespace '' already contains a definition for 'MapCamera'. What am I doing wrong?

Author: Cmig, 2019-06-09

1 answers

This error tells you that such a class already exists. Are you sure you didn't add it to the project? Try searching the folder by name.

To be more precise, the error says that it is in this namespace that the class is contained. You can add a namespace if you enclose the class in additional brackets with a special word, for example, like this:

namespace Game
{
    public class MapCamera : Singleton
    {

    }
}

This construction means that the MapCamera class is located in the "Game namespace". This will result in only classes from the same namespace will be able to " see " this class, or those classes that will have the string using Game; up, i.e. they will be given access to a specific namespace.

Classes with the same name can exist simultaneously if they are in different namespaces. But it is better not to do so, so as not to get confused)

 1
Author: M. Green, 2019-06-09 18:28:30