How do I know which "using" to use at the top of a C# script?

-I have seen a similar question here: Can someone explain 'Using ..." and "MonoBehaviour" in C# - Questions & Answers - Unity Discussions

-It doesn’t really answer how to know which using etc, I need to use. For example: I am adding in some text so I add Using UnityEngine.UI (from my memory). But I have no idea why it is specifically as it reads. The problem with this is that when I download an asset or try to use something more foreign to me, I have no idea what using etc, I have to use.

-Note: I searched the documentation based on keywords from the other similar question above, with words such as Namespace but the documentation reads very different to how people explain it.

-I am looking for a concise response with something that explains where in unity these are listed.

-Finally: I know that VS has a shortcut key that tells you which using etc. to use, so if this could be listed it could be helpful to others (I have forgotten).

As indicated in the Microsoft documentation, the using directive has three uses. The most common one allows you to use types in a namespace so that you do not have to qualify the use of a type in that namespace.

// Without `using UnityEngine.UI;` at the top of your file
public UnityEngine.UI.Button myButton ;

// With `using UnityEngine.UI;` at the top of your file
public Button myButton ;

To know which namespace you must put at the top of your file, you have to look at the documentation page of the class you are interested in. For example, the NavMesh class:

You can see the namespace just under the class name. Thus, you have to put using UnityEngine.AI; ath the top of your file if you want to use Navmesh class in your code.


For pure C# classes, the principle is the same. Go to the class’page you are interested in and you will find the correct namespace just below the class name. For the Regex class, put using System.Text.RegularExpressions; at the top of your file, and you will be able to declare a Regex as follow : Regex regex = new Regex(...);


For 3rd party libraries, nobody will do the same, so you have to hope they have a decent documentation.

For Text Mesh Pro, you can find the namespace of the TextMeshPro class just below the class name, like in the C# and Unity documentation :

TextMeshProSwitch to component

Namespace: TMPro / Inherits from: MonoBehaviour

So, you have to add using TMPro; at the top of your file.