很久以前的方法,2018.2.16是有用的。
首先在index.html页面中的标签内加入以下代码(这是官方的第一个步骤,要等打包后修改):
<script src="http://h.api.4399.com/h5mini-2.0/h5api-interface.php"></script>
位置如下:
然后,我想调用的是广告api,就在index.html的这句
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/BWeb.json");
//后面的Build/BWeb.json每个人因为打包路径不同而不同,所以不要修改成我代码里的这样。
后面插入了一个function()
function PLAYAD() {
h5api.playAd(data => {
// 做点什么
console.log('播放广告回调数据', data)
});
}
就是这样。
当然你要先在你的游戏里写个方法调用。
public void PlayAD()
{
Application.ExternalCall("PLAYAD");//这句在2018.2.16里显示已弃用,但还是有效的。更高版本就不知道了。
}
//比如这样