unity中webgl与h5互调

unity调用H5:

Application.ExternalCall(functionName, params object[] args);

第一个参数是H5中的方法名,第二个参数是H5中方法的参数(可变参数)

H5调用unity里的方法(在打包出来的index.html中加入下列代码):

//这一句是打包出来就会有的

var gameInstance = UnityLoader.instantiate("gameContainer", "Build/WebGL.json");

///这个就是H5调用unityd的方法

///第一个参数是在unity中,方法对应的脚本所挂的物体名字

///第二个参数,是要调用的方法的名字

///第三个参数,是调用方法时传的参数(好像不支持多个参数)

gameInstance.SendMessage("Scripts","SetIPAndPort","");

猜你喜欢

转载自blog.csdn.net/qq_38317140/article/details/82219793