Some of unity3d's compile-based methods can only be used in JS, And it is ineffective in C #, while C # can communicate with the server side, and JS itself won't work. Therefore, we will encounter mutual use of these two methods in the plain text. The following is an example.
Two files: test1.js and test2.cs
Test1.js
Function Ongui ()
{
If (GUI. Button (rect ( 25 , 25 , 100 , 30 ), "JS call CS " ))
{
VaRC=Gameobject. getcomponent ("Test2");
C. printtest ();
}
}
Function Testprint ()
{
Print ("CS callJS");
}
Test2.cs
Using Unityengine;
Using System. collections;
Public Class Test2: monobehaviour {
Void Ongui ()
{
If (GUI. Button ( New Rect ( 25 , 70 , 100 , 30 ), " CS call JS " ))
{
Test1 C=(Test1) gameobject. getcomponent ("Test1");
C. testprint ();
}
}
Void Printtest ()
{
Print ("JS call CS");
}
}
Note that JS files must be in either of the three categories: "Standard assets", "Pro standard assets", and "plugins, the CS file cannot be in the same project as the JS file. The reason is that the original books in these three categories are first written, later written in the "Editor" category, and other historical books are finally written. Currently, the unity3d version 2.5 does not support C #3.0, so you cannot use the VaR keyword. In this way, only the struct type is supported, therefore, if the CS file cannot retrieve the methods in JS in a single object, it cannot be used. The Cs method does not have this restriction for JS runtime.
the software-based entrance exam http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html