Namespace- C# Skill in Unity: 5

Objective: get to know the basic of namespace in Unity.

Namespace is a basic structure of C#. In Unity, you probably will not see this word too often like other basic structures such as class. However, it is everywhere when you creating or using a C# script.

Where is namespace

When you open a script at the first time using Unity, you already seen the namespace.
The top 3 lines of code is the namespace that this script had used.

The class MonoBehaviour is also under the namespace “UnityEngine”. If we delete or comment out the namespace, it should shows error under MonoBehaviour.

Missing namespace.

Namespace is a library that you can use the function in it. The rule of getting the access of that library is “using” it.
For example, you will not be able to use NavMeshAgent if you have not access the library of UnityEngine.AI, which is a namespace of AI.

Create your own namespace

When we download some assets from Unity Asset Store, there might be some conflict when the name of script is same as scripts that we already had. In this situation, we can create a new namespace to solve this problem.

Let’s assume that we create a script for Shield and also download a script called Shield. Open either script you will see the error sign like this.

Now we can create a name space and cut down the whole part of downloaded script and paste it in.

As you can see the error of conflict is gone.
And we can use the downloaded script by using the namespace we just created.

That is how to solve the conflict when downloaded a script with existed name in Unity.




A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Tech numbers and how we prepared for the biggest beauty week ( black friday ) in Brasil !

Suspicious Link

Working Hours analise: Transalting SQL To DAX

Decode the EU Green-Pass QRCode Using Java

The 5 Mistakes Ruining Your Data-Driven Strategy

A woman writing on a whiteboard as a man stands and watches

Custom Extension for Azure Functions— Part 1 — Triggers

Swift @escaping Closures for Laymen

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Making Tic Tac Toe Using Unity 2D and C#

How to use Post Processing in Unity

Generating A Semi-Random 2D Platformer Level

Unity C#: Classes & Structs