- Home /
How to mix a Javascript script and a CS script together on an object?
This is a beginner questions.
I have an object, a Camera (let's call it MainCamera).
I have a main javascript script (let's call it MainEngine) which manages about everything there is to be done. MainEngine also accesses a lot of prefab functions which are compiled and made available from the Plugins folder.
I have to add a C Sharp script (let's call is SharpEngine) to the Camera, which would manage a few specific situations, and have methods that are to be called by the MainEngine javascript.
The SharpEngine must also alter some variables in MainEngine. SharpEngine is a public class.
I tried the following basic settings which did not work yet:
- adding SharpEngine to the Camera.
- making sure all SharpEngine methods called by MainEngine are set as "public ###"
- tried to declare SharpEngine as a variable in MainEngine
- tried to make a prefab (something I've never done before) but it doesn't end up with the script, I'm missing something.
Then I read about script compilation order (here ) from other Unity Answers topics. If I move SharpEngine to one of the first compiled groups, MainEngine can access it (with GetComponent), but SharpEngine cannot access MainEngine variables.
If I move MainEngine to the first compiled group, SharpEngine now can recognize it but unfortunately, MainEngine cannot work as it no longer has access to all its other pre-compiled scripts (from plugins and such).
MainEngine needs to be in the end compiled group to work. This looks like a dead-end. But all I need now is an easy way for SharpEngine to access variables in MainEngine ; SharpEngine uses event listeners.
I'll try to code it differently meanwhile (having MainEngine try out SharpEngine variables continuously to find the status it needs and modify MainEngine variables after this) but if you have an easy answer to this problem, I would thank you greatly :)