Search Unity

Excluding camera rotation from screen orientation

Discussion in 'Scripting' started by bartofzo, Feb 14, 2018.

  1. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Hi,

    Is it possible to disable the camera from rotating when the screen orientation changes on a mobile device?
    Asking because in my game, the UI should adapt to the device orientation, but the camera should stay as is (I'm doing a top down 2D view and which direction is up doesn't matter for the game)

    So far I haven't been able to figure this out. Also tried counter rotating the camera, but this always results in one frame in which the camera hasn't been rotated back.

    Any thoughts? Thanks.
     
  2. diasrodrigo

    diasrodrigo

    Joined:
    Jul 4, 2017
    Posts:
    420
    I'm afraid that is not possible with current unity options. To do this I think you have to do manually by script or some plugin.

    Maybe the best way is block device orientation to get a fixed orientation.
     
  3. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    I want to give the user the ability to look at the game in any orientation they want... so locking the device orientation is not an option for me.

    Would it be possible to intercept an orientation change event (maybe native) before Unity handles it? One workaround I thought of would be to intercept that event... freeze the screen. Let Unity do it's thing, counter rotate the camera and then release the screen.
    But that would also require the ability to have the 'frozen' screen not to be rotated.

    Really hoping there's something that can be done. Willing to go deep if I have to.
     
  4. diasrodrigo

    diasrodrigo

    Joined:
    Jul 4, 2017
    Posts:
    420
    I was searching in the code, and I saw something. Have you already tried to use this property?

    Code (csharp):
    1.  
    2. if(Screen.orientation == ScreenOrientation.Portrait)
    3.         {
    4.             // do something
    5.         }
    6.