Search Unity

Question FullScreen in browser

Discussion in 'Web' started by HamidMac, Feb 15, 2024.

  1. HamidMac

    HamidMac

    Joined:
    Sep 18, 2019
    Posts:
    15
    Hey everyone, I build a PWA WebGL build and my fullscreen script is this simple method:

    using UnityEngine;

    public class FullScreen : MonoBehaviour
    {
    public void ToogleFullScreen(bool isFullScreen)
    {
    Screen.fullScreen = isFullScreen;
    }
    }

    the problem is when I press the button, I have to click or press a key then the full screen is applied but the F11 key works just fine. I even upload a test project here
     
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,777
    websites are not permitted to go full screen without user interaction
     
    HamidMac likes this.
  3. HamidMac

    HamidMac

    Joined:
    Sep 18, 2019
    Posts:
    15
    Thanks bugfinders.
    That's a bummer!! shouldn't pressing a button in the unity canvas be considered as a user interaction? it is just irritating that the user should click somewhere else to apply the fullscreen! is there a work around for it, I don't know can I fake a user input or something after the button is pressed?
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,777
    i think the reason your stuff isnt working is that the first click is actually focusing the game also i can click your "full screen" button twice and it goes full screen, so its like the bool is incorrect.

    for example take my PoS i really ought to work more on it game
    https://sillygames.online/DungeonDisasters/index.html

    All you need do is press space and mine leaps to full screen
     
    HamidMac likes this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,168
    Yes. This is a side effect of how input is handled by UGUI. See if this works for you.

    https://forum.unity.com/threads/enable-fullscreen-webgl.441174/#post-2852796

     
    HamidMac likes this.
  6. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    HamidMac likes this.
  7. HamidMac

    HamidMac

    Joined:
    Sep 18, 2019
    Posts:
    15
    thanks for the great free assets, a minor bug though the buttons won't change when I go fullscreen with the F11 key.
    I tested on Google Chrome and my Unity version is 2022.3.4. but it seems to handle all the other scenarios. (I just built your example scene.)