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. Dismiss Notice

how to disable rotation on mobile?

Discussion in 'WebGL' started by ewanuno, Apr 17, 2020.

  1. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    Last edited: Apr 20, 2020
  2. r8zbeh

    r8zbeh

    Joined:
    Dec 4, 2018
    Posts:
    38
    +1 for this
     
  3. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    Maybe it has to happen in the html page? Any ideas?
     
  4. r8zbeh

    r8zbeh

    Joined:
    Dec 4, 2018
    Posts:
    38
    its such a shame when you read webgl forum , its obvious that every one in every different period of time has gone through same issues for past three years and all these issues still remains !
    its been the third day im struggling with webgl issues on ios ! so far i just solved the dpi issue,looking for a responsive html/css solution for that
    then i should figure out a way to have touch input and mouse+keyboard input working together ,at this moment they're conflicting and Mobile device is kinda interpreting the mouse input scripts into touch
     
  5. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    i think it's just that nobody has posted the workarounds that they came up with. it's easy to forget about the struggle, when you've solved your problem. i'm taking it as an indication that none of the problems are particularly deep.

    i think the solution to the rotation locking is to lock the screen directly in html5, i'm currently trying to figure out how to do that, without knowing anything about html5.
     
  6. r8zbeh

    r8zbeh

    Joined:
    Dec 4, 2018
    Posts:
    38
  7. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    thanks,
    i think i'm just going to rotate the canvas/camera 90° when i detect that i'm in portrait mode, i just hope it doesn't glitch the screen when it turns. it's kind of messy but it'll do for now.
     
    r8zbeh likes this.
  8. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    this dosen't actually work though,
    am i actualy rotating the right things?
    i have this script attached to my camera, the canvas is set to my root canvas:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AntiRotationHack : MonoBehaviour
    6. {
    7.  
    8.     //rotate the screen 90° when we are in portrait mode
    9.     // a nasty hack untill unity webgl sorts it out.
    10.  
    11.     public Canvas canvas;
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.      
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         //do this only on mobile, it would suck if you just resized your screen on desktop
    22.         if (Application.isMobilePlatform)
    23.         {
    24.             Debug.Log("running on mobile platform");
    25.             //only when the vertical screen dimension is greater than the horizontal
    26.             //Screen.currentResolution.height > Screen.currentResolution.width
    27.             if (canvas.pixelRect.height > canvas.pixelRect.width)
    28.             {
    29.                 gameObject.transform.eulerAngles= new Vector3(0,0,90);
    30.                 canvas.transform.eulerAngles = new Vector3(0, 0, 90);
    31.                 Debug.Log("screen h" + canvas.pixelRect.height + "w" + canvas.pixelRect.width);
    32.                 Debug.Log("rotate 90°");
    33.             }
    34.             else
    35.             {
    36.                 gameObject.transform.eulerAngles= new Vector3(0,0,0);
    37.                 canvas.transform.eulerAngles = new Vector3(0, 0, 0);
    38.                 Debug.Log("screen h" + canvas.pixelRect.height + "w" + canvas.pixelRect.width);
    39.                 Debug.Log("rotate 0°");
    40.             }
    41.  
    42.         }
    43.     }
    44. }
     
    r8zbeh likes this.