Interaction between CS scripts and JS scripts in Unity
Note that the called scripts must be placed in any of the three folders, Standard Assets, Pro Standard Assets, and Plugins. The scripts called cannot be in one directory folder, otherwise, the compilation will fail because Unity will first compile these three folders, the scripts in the "Editor" Directory will be compiled later, and other scripts will be finally compiled (Both CS calls JS, CS scripts should be put in other file homes. JS scripts should be put in three folders for compilation first; JS calls CS, JS scripts should be put in other folders, and CS scripts should be put in three folders for compilation first)
I. CS calls JS scripts
JsMM. js
// Method in the JsMM Script function spoken () {print (js );}
Test. cs script
Public class Test: MonoBehaviour {void OnGUI () {if (GUI. button (new Rect (50,150,100, 50), diaoyong JS) {// get JsMM script JsMM js = (JsMM) GetComponent
(); // Call the method js. spoken () ;}} In the js script ();}}}
Place both JsMM. js and Test. cs on an object and run the command.
Ii. JS calls CS
CsMM. cs script
using UnityEngine;using System.Collections;public class CsMM : MonoBehaviour { public void AAA() { Debug.Log(aaaaaaa); }}
JsCode. js
//#pragma strictfunction OnGUI(){ if (GUI.Button(new Rect(50, 300, 100, 50), JS DIAO YONG cs)){ var csMMScript = gameObject.GetComponent(CsMM); csMMScript.AAA(); }}