C# NameSpace in Unity3D
NameSpace allows users to distinguish and organize scripts from one another. You can have two scripts with the same name without any naming confliction. Code can be easily imported into projects regardless of its current stage of development with NameSpace.
Creating 2 Scripts named weapon and using both on one Game Object.
by Default, unity uses three name spaces so we can use monobehavior methods and other methods we use to create our games.
These two scripts are both named weapon and are on one game object. Whats separating them from one another is their namespace.
name space simply wraps over the entire class to be able to give it a name space.
To access a variable or function from either script, I would insert their name spaces above. Just like unity name spaces.
Another use for this is to be able to extend a script for greater functionality. An example here would be making an ammo system for the PicoWeapon.
once using PicoWeapons is declared above. I can reference the script like any other script. in this case; Picoweapon.Weapon Picowep;.
the reference here gets assigned a game object that has the attached script. It will get the component of the script ,’Weapon’ so that we can access the Ammo int variable.
The Ammo variable is incremented when the attached game object collides with a trigger. If the collider has a tag named ,’Pico’. Then The ammo variable in the weapon script will increment.
Namespaces are particularly useful when working in teams or distributing your content. This is a great way to avoid script conflicts with having the same name. Namespaces allows assets to be imported seemly regardless of what stage of development the project is in. Additionally its another way to extend the functionality of other scripts.