The CS script in unity interacts with the JS script

Source: Internet
Author: User

It is important to note that the script being called must be placed in the"Standard Assets","Pro standard Assets"and the"Plugins"any one of these three folders, and the script that calls it cannot be in a directory folder, otherwise it cannot be compiled, becauseUnitywill compile these three folders first,"Editor"the script in the directory is compiled later, and the other scripts are finally compiled (bothCScalledJS,CSThe script is placed in the other file home,JSthe script should be placed in the above three folders first compiled;JScalledCS,JSThe script is placed in a different folder,CSscript to be placed in the above three folders first compiled)


First, CS Call JS script

Jsmm.js

    Jsmm Script method    function spoken ()    {        print ("JS js JavaScript js js  ");    }

Test.cs Script

public class Test:monobehaviour {    void Ongui ()    {        if (GUI. button (new Rect ((), Diaoyong js))        {            //Get JSMM script            jsmm js = (JSMM) getcomponent<jsmm> ();            //Call the method in the JS script            js.spoken ()        ;    }}


Hang the jsmm.js and Test.cs on one object and run



Second,JS Call 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 (a), "JS  DIAO YONG cs") {        var csmmscript = gameobject.getcomponent ("csmm");        CSMMSCRIPT.AAA ();    }}


Can be run


Note the comments in the JS script //#pragma strict or it will be an error. method in CS script not found






The CS script in unity interacts with the JS script

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.