最近做了一个项目,要求unity打包出webgl,并在手机上运行(iOS,安卓),发现在测试中会出现一个弹框的问题(如图);

查找一番后发现:

这个问题其实是在你unity打出webgl工程后 Build/UnityLoader.js 中,一般打开后没有格式,建议格式化后查看更方便直观(在线格式化,度娘就能轻松找到一堆,这里就不说出来了,当然你想要也可以私信我推荐你我用的);

找到下面这段代码:(建议直接ctrl+f查找t(),或者查找 Blobs: {},

 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
        }]) : ["Edge", "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
        }])
    },
    buildCompatibilityCheck: function(e, t, r) {
        function n() {
            if ("undefined" == typeof e.graphicsAPI) return ! 0;
            for (var t = 0; t < e.graphicsAPI.length; t++) {
                var r = e.graphicsAPI[t];
                if ("WebGL 2.0" == r && 2 == UnityLoader.SystemInfo.hasWebGL) return ! 0;
                if ("WebGL 1.0" == r && UnityLoader.SystemInfo.hasWebGL >= 1) return ! 0;
                e.print("Warning: Unsupported graphics API " + r)
            }
            return ! 1
        }
        n() ? !UnityLoader.SystemInfo.hasThreads && e.multithreading ? r("Your browser does not support multithreading.") : t() : r("Your browser does not support any of the required graphics API for this content.")
    },
    Blobs: {},

找到后复制下t(),进行如下删除替换修改

    compatibilityCheck: function (e, t, r) {
        t()
    },
    Blobs: {},

然后保存代码,运行就会发现没有任何弹框,这是强制性的一种方法;不会有任何弹窗提示(个人测试无问题,安卓iOSpc皆可)

unity打webgl问题我已踩坑(iOS不能播放视频问题,碰撞和触控冲突问题,webgl修改unity logo问题)有这方面的可联系我探讨解决。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐