一、unity调用web的js函数

在unity中写如下调用语句:

Application.ExternalCall( "SayHello", "The game says hello!" );

 

在html中定义函数如下

function SayHello(args){
    alert(args);
}

二、在web中用js调用unity对象函数

在unity中定义函数如下,并将脚本绑定到名为Interface的GameObject中

function createOutTask(){
    GameObject.Find("CreateOutTask").GetComponent(CreateOutTask).createOutTask();
}

在web中调用unity对象时,需特别注意使用的unity的版本

3.5及以前版本,调用如下:

GetUnity().SendMessage("Interface", "createOutTask", "")

 

4.0版本,调用如下:

var config = {
    width: 1730, 
    height: 980,
    params: { enableDebugging:"0", disableContextMenu: true }
    
};
var u = new UnityObject2(config);

u.getUnity().SendMessage("Interface", "createOutTask", "");
对于4.0版本的调用,参照官方文档http://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html
Note: keep in mind that if the function doesn't have any arguments, then an empty string ("") should be passed as an argument.

转载于:https://www.cnblogs.com/huntdream/archive/2013/04/19/3031629.html

Logo

电影级数字人,免显卡端渲染SDK,十行代码即可调用,工业级demo免费开源下载!

更多推荐