programmer3
programmer3

Reputation: 137

Unity C# global namespace

Im having problems with global name spaces in Unity With C#

I have the following code in two separate files

FILE: MyUtil.cs

using ....
using ....

public class MyUtil :  Photon.PunBehaviour
{
  public static IEnumerator DoStuff(string link)
  {
      WWW sss=new WWW(link);
      yield return sss;
  }
}



FILE: TestClass.cs

using ....
using ....

namespace NewNameSpace {
  public class TestClass : MonoBehaviour
  {
     public void useIt()
     {
       StartCoroutine(global::MyUtil.DoStuff("www.link.com")); <<< error here
     }
  }
}

Im getting error on the StartCoroutine line saying that MyUtil class itself is not found in the global namespace.

I want to call MyUtil.DoStuff from useIt method, but it wont compile.

Anybody knows why?

Thanks

Upvotes: 2

Views: 2509

Answers (2)

programmer3
programmer3

Reputation: 137

Scripts in the Plugins folder cant see scripts in other folders, but scripts in other folders can see scripts in Plug in.

The script that was giving me problems was located in the Plugsins folder.

This is what caused the problem, so I moved the scripts from plugins to another folder and everything worked.

Thanks everybody for your comments and help.

Upvotes: 3

Jerry Switalski
Jerry Switalski

Reputation: 2720

MyUtil is a MonoBehaviour, and as far as I know, the name of that component needs to match with the file name. If not, Unity won't compile it.

That is why compiler cannot find it.

To fix this, change the name of util.cs to MyUtil.cs.

Upvotes: -1

Related Questions