JavaScript and namespaces for your helper classes

Is there anyway to have the same class name contained in two separate scripts? Can I make a class private, or what do I want to do here?

Script A:

@script System.Serializable
class MyClass { var foo = 0.0; }

var MyClass myClass;

Script B:

@script System.Serializable
class MyClass { var foo = 0.0; var bar = 0.0; }

var MyClass myClass;

error BCE0132: The namespace ‘’ already contains a definition for ‘MyClass’.

Am I absolutely required to just rename these?

Thanks,
-Jon

Why not just use the same class, or inherit from it?

In the actual classes, not the trivial example above, they are much different from each other. Neither sharing a class nor inheritance makes any sense. These are helper classes and their scope should be limited. It’s what namespaces are for. But how namespaces and Unity’s JavaScript work is not clear or documented as far as I know.

-Jon

It’d also be convenient if user-defined classes were in a different namespace than built-in Unity classes. I ran into problems when I inadvertently named a script the same as a built-in class.

It doesn’t seem user-defined (unless via compiled .dll’s?) namespaces are supported…

Point 5: http://unity3d.com/Documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html

In C# you can create a class within your class that inherits from MonoBehaviour, and its scope is contained in there. So it is possible to have a class in ClassA called the same thing as a separate class inside of ClassB. In Unity’s Javascript, your helper classes seem to be on the same scope as the implicit MonoBehaviour inheriting class created with the script. All I’m asking if there is any way to mimic what can be done with C# in this case.

ClassA.cs...
public class ClassA : MonoBehaviour {
	[System.Serializable]
	public class Helper {
		public float bar;
	}
	
	public Helper foo;
}

ClassB.cs...
public class ClassB : MonoBehaviour {
	[System.Serializable]
	public class Helper {
		public float foo;
		public float bar;
	}
	
	public Helper foo;
}

ClassA.Helper and ClassB.Helper can peacefully coexist. Again, just an example here. Using namespace Foo { … } in C# isn’t the topic, here.

Cheers,
-Jon