Table of Contents
WebGLCallbackHandler
The WebGLCallbackHandler is a prefab you can add to your scene(s) so that you can send messages back and forth from your Unity Instance, to the browser.
As of Version 2.5.0 The LivelyWebGL API looks for the WebGLCallbackHandler at runtime and if none exists it creates one with gameobject flags set to hidden (So you wont see it in the hierarchy). No audio source or mixers are added to it. Add the prefab to your scene to pause / mute your audio.
Tap To Start Usage
The template offers a Tap To Start Screen(TTSS) that by default is activated after the game finishes loading.
Once the TTSS is enabled the browser sends a message to unity looking for the WebGLCallbackHandler.
There is a method on the WebGLCallbackHandler called PauseGame() which is called by the browser immediately after the game has loaded - which effectively Pauses the game by settings Time.timescale to 0.
NOTE: The prefab offers an AudioSource and AudioMixer parameters which will be paused / muted at runtime when PauseGame() is called.
After the user has made a click or tap gesture, the browser sends a message to unity looking for a method Called ResumeGame() on the WebGLCallbackHandler, which sets the Time.timescale back to 1
NOTE: The AudioSource and AudioMixer will be unpaused / unmuted when ResumeGame() is called.
Keep in mind that anything that runs in Awake, OnEnabled, or Start will continue to run. Once the lifecycle reaches Update, then timescale takes effect.
https://docs.unity3d.com/Manual/execution-order.html
Unity Lifecycle vs. Time.timeScale Awake → OnEnable → Start These all happen before the first Update loop. They are not affected by Time.timeScale. Unity runs them immediately when the object is created/enabled. Update, FixedUpdate, Coroutines, Animations, Physics These are the things affected by Time.timeScale. With 0, they don’t advance.
Note: Audio does not pause automatically when Time.timeScale is set to 0 - This must either be started manually, or you can use the WebGLCallbackHandler Prefab and fill in the correct audio parameters depending on your needs.
