Answer the question
In order to leave comments, you need to log in
How to make fullscreen work in Unity WebGL from the first click?
Good evening, such a problem. I made a fullscreen button in the game and it only works on the second release of the key (that is, it does not process the event on the first click).
Wrote js plugin:
var ScreenOpenerPlugin = {
ScreenOpenerCaptureClick: function() {
var OpenScreen = function() {
parent.setFullscreen(parent.document.getElementById("gameContainer"));
document.getElementById('#canvas').removeEventListener('mouseup', OpenScreen);
};
document.getElementById('#canvas').addEventListener('mouseup', OpenScreen, false);
}
};
mergeInto(LibraryManager.library, ScreenOpenerPlugin);
using System.Runtime.InteropServices;
...
[DllImport("__Internal")]
private static extern void ScreenOpenerCaptureClick();
...
private bool stateTmp = false;
public void SetFullscreen() {
if(WinPanelAnim.gameObject.activeSelf) {
return;
}
ScreenOpenerCaptureClick();
ButtonClickSound();
stateTmp = Screen.fullScreen;
Screen.fullScreen = !Screen.fullScreen;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question