Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity3d Screen.orientation not forcing screen to rotate on scene initialization

Discussion in 'Scripting' started by Deleted User, Sep 19, 2018.

  1. Deleted User

    Deleted User

    Guest

    Hi Guys,

    I have two scenes in my application.

    First Scene is in landscape mode
    and the second one support both Landscape and portrait.

    My First Scene Start Method is
    void Start()
    {
    Screen.orientation = ScreenOrientation.Landscape;
    }

    and second scene Start Method is
    void Start()
    {
    Screen.orientation = ScreenOrientation.AutoRotation;
    }


    I assume that this should force the screen to rotate and stay in the specified rotation. However, when I go from scene 1 to scene 2, it does not force the orientation on scene initialization, instead, if I am switching from the first scene to the second, the screen stays in landscape orientation as long as I don't move the device. When I move the device in any direction, the screen changes to specified orientation. For whatever reason, this does not apply when going from scene 2 to scene 1: the screen rotates properly, no matter its previous rotation. I find this really frustrating as the UI in the second scene is designed to be viewed in both landscape and portrait mode and it is inconvenient to move the device every time you try to change scenes. So am I missing something or is this a bug?

    Any help would be much appreciated
     
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    Please use code tags...
    ScreenOrientation.AutoRotation
    specifies that the orientation is unlocked to change. It does not change the orientation until the device detects it being in another orientation.

    https://docs.unity3d.com/ScriptReference/Screen-orientation.html
    If the value is set to ScreenOrientation.AutoRotation then the screen will select from any of the options (enabled by autorotateToPortrait, etc) automatically as the device orientation changes.


    https://docs.unity3d.com/ScriptReference/Input-deviceOrientation.html
    You can use the Device Orientation and set the Screen Orientation accordingly when setting it to auto rotate.
     
    Deleted User likes this.