I created a class I called Limit in Javascript to make it easier to use from the Editor (at least I feel like it’s easier :)).
But it seems like I have to create it for each script requiring it. Is it possible to create it in a separate file (ie : CustomClass.js) and call something like var myLimits : CustomClass.Limit;
from the files requiring a variable of this type?
Additionnaly, can the same thing be done for enums?
Thanks a lot.
EDIT : OK, I should have tried the easiest solution first. No change required from my good old var myLimits : Limit; even if I the definition is in another file. The namespace is for the whole project so, no problem.
Scripts saved in the Standard Assets folder can be accessed by other scripts outside of Standard Assets. Say your class/script is in /Standard Assets/Scripts/Limit.js and the accessing script is in / Scripts/Foo.js:
Yes, thanks for pointing that out.
My “Limit.js” and “Foo.js” scripts are currently both under “Scripts” so they have the same “level”. If my Foo.js was to be moved under “Standard Assets/Scripts”, then yes, it wouldn’t work.
Well, to be precise, let’s say I’m trying to “merge” specific class definitions I have in various JS files into a common one, and access them from any other script of my project.
So what I want to do is have a “SpecificClasses.js” file (with my Limit class) and then several “Foo1.js”, “Foo2.js”, etc. files that can have one or more Limit variables.
This way I could have :
//SpecificClasses.js
class Limit
{
var min : float;
var max : float;
}