Relationship between namespaces and folders

Viewed 316

Hi all I have a problem with namespaces.

As you can see the Standard Assets are imported but the script does not see the UnityStandardAssets namespace.

namespace can't be found

But if I create a new script inside the Assets/Standard Assets/Characters/FirstPersonCharacter/Scripts/testScript.cs there is no problem

namespace resolved

Clearly there is some kind of relationship between namespaces and folders that I do not understand. I would very much appreciate if somebody could shine some light on the subject.

1 Answers

No they are no relation between namespaces and folders, but in general its common usage to adapt the namespce with name folder. when you are using an externall, the contains specified namespaces..

so in same project you could write that

namespace toto { public class titi{} }

namespace tata { public class titi{} }

and if you want to use titi in namespace tata

you write

var t = new tata.titi();

or put

using tata;
var t = new titi(); 

but its good usage to use namespace, for example when you want to categorize some part of program.

so in your sample, you could put off the unused using directive (namespaces) (quick fix does the operation)

By default all classes that don't have an explicit namespace belong to global namespace, so even when you are not writing any namespace you are using one

Related