Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Going Fullscrren on WEBGL?

Discussion in 'Web' started by KasunL, Aug 4, 2023.

  1. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    (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!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,162
    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:

    https://va.lent.in/opening-links-in-a-unity-webgl-project/

    You drop in the jslib, then call it from a
    [DllImport("__Internal")]
    interop
     
    KasunL likes this.
  3. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    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..
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,316
    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.
     
    Kurt-Dekker and KasunL like this.
  5. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    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..
     
  6. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    392
    Player clicked, you made the whole app a button. It's not automatic.
     
    KasunL and bugfinders like this.
  7. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    848
    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
     
  8. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,514
    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,
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3. using UnityEngine.UI;
    4. public class FullscreenButton : Button
    5. {
    6.   public override void OnPointerDown(PointerEventData eventData)
    7.   {
    8.     base.OnPointerDown(eventData);
    9.     Screen.fullScreen = !Screen.fullScreen;
    10.   }
    11. }
    Then create UI->Canvas and add a UI->Legacy->Button, remove the Button component from it and add your FullscreenButton component.
    example_webgl_fullscreen_button.png
    Then your test should look like this in your scene:
    example_webgl_fullscreen_button_in_scene.png
     
    KasunL likes this.
  9. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    Thanks! I'll try that and report back.
     
    adamgolden likes this.
  10. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    848
    I used pressing of space which loaded the next scene and also went full screen.