How do I clean up and unload a Unity WebGL canvas when changing page

后端 未结 2 393
说谎
说谎 2020-12-18 09:33

I\'ve got a problem on my web application when I am changing the current page after downloading and running a Unity WebGL game.

In fact, I know for sure

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 10:23

    The solution is simple: load the WebGL unity in an iframe, this sandboxes the application.

    When you're done with the unity app just remove the node of the iframe like:

    var iframe=...;
    iframe.parentNode.removeChild(iframe);
    

    And it and all of it's resources should be instantly unloaded.

    You can't communicate with the Unity player directly when you're in an iframe but you still can pass messages to and from it with postMessage.

提交回复
热议问题