enable = false JS components on another GameObject with C#

pretty much as the tittle says

You need to set the order of script compilation in order for your C# script to be able to access the script component and variable from JS script since C# scripts are compiled before JS scripts normally.

So set your JS script to execute before your C# script using one of the methods from above manual articles. Then you can access your JS script from C# script of yours.

Your description should be more, well “descriptive”.

You might already know the fact that Unity compiles each language it supports independently from each other to a seperate assembly. That’s why classes from other languages aren’t visible during compile-time.

Unity has a partial solution as each language actually compiles the script in “4 waves” while onle 2 of them affect runtime scripts. Generally things that get compiled last can use everything from the first wave of other languages. Unity actually creates two assemblies for each language, one for each compilation step. That allows the compiler of the second wave to reference the assemblies of the first.

However if you just want to enable / disable a component you can simply rely on MonoBehaviour inheritance by using the string version of GetComponent:

// C#
MonoBehaviour someJSClassInstance = someGameObject.GetComponent("TheJSClassName") as MonoBehaviour;
someJSClassInstance.enable = false;

This wouldn’t require you to place your scripts in certain compilation order.

ps: personally i strongly recommend to not mix languages as this can create too much trouble. It might be fine to use some of the UnityScript standard assets (which are already in the first compilation wave) as they usually aren’t changed, but besides that keep the mixing to a minimum.