A
A
Alexander Kusak2018-11-14 18:59:04
JavaScript
Alexander Kusak, 2018-11-14 18:59:04

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);

Integrate it into the script:
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;
  }

For the first time, the code executes and changes the value of the variables, but does not intercept the event for releasing the mouse button, the second time I press the button and the screen opens in fullscreen, but when the button is released, everything returns to the normal version again.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question