Call a Class out of current namespace

Hi I am searching through the forums on this topic:

I have a namespace inside my unity project:

namespace MyCompany.Proj1
{
    class MyClass
    {
public void method(){
// I want to call a method out of MyCompany.Proj1
    }
}

How can I do this?

Thank you

In the calling class you will need to do something like:

using MyCompany.Proj1;
// other stuff you want to use.

// some other namespace
public class OtherClass
{
  public void SomeMethod()
  {
    MyClass mc = MyClass();
    mc.method();
  }
}

If you expect to call a method as a class method and not an instance method(where you instantiate an object), you will need to mark the method as static.

Example:

namespace MyCompany.Proj1
{
  class MyClass
  {
    public static void method(){
    // I want to call a method out of MyCompany.Proj1
  }
}

To be accessible outside of the namespace a class must be public.

As indicated previously you can use the fully qualified name. Alternatively you can put a using statement at the top of your script.

General advice is if you can’t figure this all out on your own then you are probably better off without namespaces.

Add a reference to the project.

Say you are working in project 2, and want to access a class from project 1

then go to project 2, open the solution explorer and where u see references right click and click add reference, then go to projects and grab project 1.

Now all you have to do is add a using, if your script in project one has

namespace Assets.Scripts {

}

then in project 2 in the class you are working in you will have to add

using Assets.Scripts;