2

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

14
  • It should just work without the global::, have you tried? Commented Aug 15, 2016 at 18:49
  • Yes i tried it without the global::, and also tried "global." but no work either :( Commented Aug 15, 2016 at 18:53
  • Do you have util.cs in your assets folder or is it a file on your hard drive? Can you edit your question with a screenshot of the assets folder with these two files? Commented Aug 15, 2016 at 18:55
  • Actually i typed the name wrong in here, its actually MyUtil.cs, not util.cs, sorry about that. But it still doesnt work! Commented Aug 15, 2016 at 18:57
  • Why not update your question and fix it? Also put complete of what both scripts looks like. This will help people replicate your problem. Commented Aug 15, 2016 at 19:02

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Not work for me.
-1

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.

1 Comment

Thanks for the comment, actually the file is already MyUtil.cs (I typed it wrong in here)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.