1.窗口自适应问题
unity打包好WebGL包体时生成index.html,用文本编辑器打开修改里面的代码
在<script>添加Reset()函数
<script>
function Reset()
{
var canvas = document.getElementById("#canvas");//获取#canvas
canvas.height= document.documentElement.clientHeight;//获取body可见区域高度
canvas.width = document.documentElement.clientWidth;//获取body可见区域高度
}
</script>
在<body>里面调用函数,并修改长宽占比
<body>
<body onresize="Reset()" ,scroll= no, style="overflow:hidden">
<div class="webgl-content"style="width: 100%; height: 100%" >
<div id="gameContainer" style="width: 100%; height: 100%;margin:auto" ></div>
</div>
</div>
</body>
2.unity webgl 移动端 去掉提示框
每次用移动端打开时都要跳出:Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway. 然后点击OK就可以了,去掉方法1.打开打包好的文件如图所示(最终打开UnityLoader.js)
//UnityLoader.js 里面替换下面函数就可以了
compatibilityCheck:function(e,t,r){
UnityLoader.SystemInfo.hasWebGL?
UnityLoader.SystemInfo.mobile?
t()
:["Firefox","Chrome","Safari"].indexOf(UnityLoader.SystemInfo.browser)==-1?
t()
:t()
:e.popup("Your browser does not support WebGL",[{text:"OK",callback:r}])
},
// compatibilityCheck:function(e,t,r){
// UnityLoader.SystemInfo.hasWebGL?
// UnityLoader.SystemInfo.mobile?
// e.popup("Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway.",[{text:"OK",callback:t}])
// :["Firefox","Chrome","Safari"].indexOf(UnityLoader.SystemInfo.browser)==-1?
// e.popup("Please note that your browser is not currently supported for this Unity WebGL content. Press OK if you wish to continue anyway.",[{text:"OK",callback:t}])
// :t()
// :e.popup("Your browser does not support WebGL",[{text:"OK",callback:r}])
// },
Blobs:{},loa...(省略)
修改如下:最近看到一篇文章不用每次打包出来编译修改点击查看自动化打包
自己亲测可以成功,如有问题欢迎留言