Interaction between CS scripts and JS scripts in Unity

Source: Internet
Author: User

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();    }}

 

 

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.