- Home /
calling c# function from a js file..
public class className : MonoBehaviour {
public static void record() {
blah blah..
}
}
i want to call above record function from a js file...how can i do that ..
already tried this "className.record();" but its not working.
i want to call the record function here..
this is the code of java file.
if(hit.gameObject.tag == "Ball")
{
//code to call the record function
}
what else method could be to call the record function from a js file.i am using unity 3.5 pro.
Answer by whydoidoit · Sep 19, 2012 at 10:47 AM
UnityScript and C# scripts are compiled into different assemblies. You need to put the C# in a folder called Plugins or Standard Assets and it will be accessible from the JS file.
Note that the scripts pu into Plugins or Standar Assets cannot use or reference scripts that are outside those folders.
Just to expand on the above : it is possible to use both languages, but they need to be organized into a specific folder that gets compiled before the other scripts. See point 3 in the first link regarding these folders : All scripts in "Standard Assets", "Pro Standard Assets" or "Plugins" are compiled first. i.e. If C# files are placed in one of the above mentioned folders, C# gets compiled before JS, JS can see C# but C# cannot see JS :
http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html => point 3
http://answers.unity3d.com/questions/208383/referencing-a-c-component-script-from-js-script.html
http://answers.unity3d.com/questions/243112/calling-c-classes-from-js.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
AdjustCurrentHealth 1 Answer
Distribute terrain in zones 3 Answers
private Vector3 function? 2 Answers
Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer