I have a .js that is accessed from a C# script so I placed my .js in plugins and all works fine, but I also want the .js to access the same C# script but is that possible because the .js is compiled first I get the error …
The name ‘TestScript’ does not denote a valid type (‘not found’).
I put the .js in plugins to compile first so the C# script can see it and access it, but when I put a ref (TestScript) in the .js to the C# script I get the error.
Is this possible?
I think you’re running into this issue due to an issue with design and encourage you to re-evaluate your design.
Beyond that, some info that sheds some light specifically related to this is:
- js files are compiled before cs files
- to get a cs script compiled before js, you’d have to add the cs script to a special folder, such as Standard Assets
The point is that one will be complied before the other in 2 different steps and thus you’ll need to make the decision of which one is referencing which…but they can’t both reference each other.
Another possible work around would be to convert your js script to c# or vice versa so that they can both be compiled during the same step.
Thanks everyone for the input, but the way I’ve decided to go is, make a globalVar.js holding all the variables that the C# and .js use and need to share, place it in the plugin folder to compile first, update it at Start() from each script, then use and update at runtime, then the two scripts can happily access and share the data.
The reason I don’t want to convert one or the other is that the scripts are quiet large and access other scripts, so then I loose connection to other scripts, so it’s a knock on effect.