将.js文件放到Standard Assets目录下,否则无法编译通过

Unity Js与C#脚本通信

 

CS_test.cs :

using UnityEngine;
using System.Collections;
 
public class CS_test : MonoBehaviour {
 
    void OnGUI()
    {
        
        if(GUI.Button(new Rect(100,170,200,100),"C#调用JavaScript"))
        {
             //获取JavaScript脚本对象
             JS_test jsScript = (JS_test)GetComponent("JS_test");
             //调用JavaScript脚本中方法
             jsScript.CallMe("我来自C#");
        }
 
    }
    
    public void CallMe(string test)
    {
        Debug.Log(test);
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2021-11-28
  • 2021-12-14
  • 2021-04-18
  • 2022-01-15
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2021-07-15
  • 2021-09-26
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案