- Home /
javascript call a method from c sharp and vise versa
is it possible for a javascript class to able to call a method from a c sharp class and vise versa? if possible, how to do it?
Answer by DaveA · Nov 09, 2011 at 09:55 PM
Yes, but if you are getting errors, you may have to move your js files to the Standard Assets or Plugins folder. You do it like anything else in that language:
var csharp : CSharpClass = GetComponent(CSharpClass);
or
JavascriptClass jscript = GetComponent("JavascriptClass");
or any of the syntax variations in then scripting manual
Read the Unity documentation on compilation order. It works only in one direction because the script you want to access has to be in an earlier compilation group. If you put your UnityScript(Javascript) script into Standard Assets you can access it from any C# script that is not in this compilation group.
But it's not possible the other way round (access the C# script from JS). Only when you the two scripts switch their locations.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Script activate after amount of time 3 Answers
Unity Class Serializable C# to UnityScript 1 Answer
Randomly Generated Objects 1 Answer