新建个场景
using UnityEngine;
using System.Collections;
public class csScript : MonoBehaviour {
void OnGUI()
{
if(GUI.Button(new Rect(100,170,200,100),"C# call JS"))
{
jsScript js = (jsScript)GetComponent("jsScript");
js.CallMe("I came from C#");
}
}
public void CallMe(string str)
{
Debug.Log(str);
}
}
再新建一个 jsScript脚本(Standard Assets目录)
#pragma strict
function OnGUI()
{
if(GUI.Button(Rect(100,50,200,100),"JS call C#"))
{
var cs = this.GetComponent("csScript");
cs.CallMe("I came from JS");
}
}
function CallMe(test:String)
{
Debug.Log(test);
}
两个脚本都附加给Main Camera
C#和JAVA的脚本都试过,都有这种问题,而且不是所有编码都
出,一些简单的脚本,比如旋转物体脚本就能用(就一行代码)