Going Fullscrren on WEBGL?

(Forgive the typo in the Title)

Hi all!

I know I can use Screen.fullScreen property to make a Windows standalone game go fullscreen. But this doesn’t work in WebGL platform, right? Is there any C# function / property I can use to go fullscreen on webgl platform? Or is the only way to edit the javascript/jason (which I have no clue about) to achieve fullscreen?

Thanks!

There should already be a fullscreen button built into the generated HTML so you can see what it does.

I’ve never tried signaling the underlying mechanism myself through code but I imagine it is possible from C#?

And yes, it is editing javascript but it’s not bad: you just add a micro-snippet .jslib file I think.

Here’s how you get HTTPS links to open, for instance, so I imagine the mechanism would be the same:

You drop in the jslib, then call it from a [DllImport("__Internal")] interop

1 Like

Thanks for the input.

Though the problem is my current game is on Newgrounds, and once I upload it there, I cannot open another webpage using window.open(url);, I think. And I’m not sure if there’s a C# code for WebGL for going fullscreen. even in Player Settings there’s no fullscreen option such as in Standalone player Settings.

The problem with the built-in Blue fullscreen button inside the iframe is that, my game screen resolution is 1920 x 1080 and it gets out-of-bounds of the webpage when loaded, hiding the blue button. So the people complain the resolution is broken. If I just could go fullscreen when the player clicks on the game screen, that problem won’t occur…

You cannot force a webgl app to enter fullscreen. The user has to make that action through the browser. Imagine the possibilities for abuse if a browser app could enter fullscreen just like that, possibly showing some fake Windows desktop or a login screen of a service so that the user enters private date thinking he is on the actual service website.

2 Likes

Though what’s funny is, sometime ago I seemed to have done just that (not the abuse part, but auto-fullscreen thing) in one of my WebGL games HERE (GameJolt.com). After the loading screen, when the player clicks inside the game screen, it automatically goes fullscreen. I have no recollection of how I did that then…

Player clicked, you made the whole app a button. It’s not automatic.

2 Likes

they made it so webgl had to press a key or click a button due to i guess somethings having bad behaviours and stopping people getting rid of them etc. So yes, you have to click or press a button. easy way to do it is as first screen have a welcome screen and on clicking/pressing any key, do th full screen then

There is a way I’ve just confirmed still works in latest LTS (2022.3.6f1), tested in Chrome, Edge and Firefox on Windows. Using pointer down event was the suggested way ages ago - I don’t use any of the Unity UI systems anymore so I’m not sure if there’s a newer approach, but you can do this.

Create a script, call it whatever like FullscreenButton,

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class FullscreenButton : Button
{
  public override void OnPointerDown(PointerEventData eventData)
  {
    base.OnPointerDown(eventData);
    Screen.fullScreen = !Screen.fullScreen;
  }
}

Then create UI->Canvas and add a UI->Legacy->Button, remove the Button component from it and add your FullscreenButton component.


Then your test should look like this in your scene:

1 Like

Thanks! I’ll try that and report back.

1 Like

I used pressing of space which loaded the next scene and also went full screen.