- Home /
Assigning value to variable from JS script via C# script
Hi everyone!
The method I'm currently doing right now is that I attached the JS script on an empty GameObject then I'm trying to access it via script by
GameObject.Find("MyGameObject").GetComponent<MyJSScript>();
However, the "MyJSScript" is not appearing in the suggestions.
Converting my script to C# is not an option bc as well bc i am trying to access a lot of js scripts in my main JS file and it would take too much time if i convert them all. Any heads up would be much appreciated
Answer by Cuttlas-U · Sep 25, 2017 at 09:02 AM
hi;
java script wont be show in suggestion in c# scripts ; if u have no error writing the code above in the editor then u are ok , but if u have compilers error u have to do like below ; ================== u have to put your js file inside one of the main unity Folders like "Plugins" folder or "Standard Asset" folder if u don't have these folders u can create them ; but c# scripts should be out side of these folders ; the scripts in these folders will be compiled first;
so now u can access them like a usual c# access like u wrote above ; (it may still dont show any suggest but there will be no error )
notice that c# scripts should be out side of these folders ( u can not put both of them in these folders if u want to access java from c# )
===========================================================
should know that "JS" will be deleted from unity engine soon ; so u better change or convert all of your java script ;
=======================