- Home /
Is it possible to rotate the entire screen orientation?
I want to rotate the entire display output for a PC standalone build, the same way you'd expect a mobile app to rotate when you rotate the device (i.e. "Screen.orientation").
The goal is to create a TATE mode so the game can be played on portrait monitors like an arcade cabinet game.
I've managed to achieve a similar effect by changing the Windows display settings, but I want to do it in-game so users don't have to do that whenever they play the game.
Is that even possible? And if so, how?
Thanks!
Answer by AaronXRDev · Nov 02, 2018 at 08:38 PM
Certainly! If you don't want to change the screen resolution in Windows you could always just rotate your camera -90 on the z axis.
Your UI and controls would also have to be rotated accordingly.
One way to rotate your canvas would be to add a Grid Layout Group to it:
I set the cell size to be my screen resolution and made sure I set the canvas to Screen Space Overlay.
Next I added a layout object that could be set to fill the whole screen and contain all my UI items. That item should be set to fill the whole screen. I added all my UI elements under it.
Finally I added a script to my canvas. The script has a "tateMode" boolean to track the current state and rotates the camera and UI to match. The script I made is below, and I've zipped the whole project and attached it so you can test it out. I think using this the controls could remain the same.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FlipToTATE : MonoBehaviour {
private bool tateMode;
public GameObject myCamera;
public GridLayoutGroup myGrid;
public RectTransform layoutRotator;
// Use this for initialization
void Start () {
tateMode = false;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyUp(KeyCode.Space))
{
tateMode = !tateMode;
if (tateMode)
{
myCamera.transform.eulerAngles = new Vector3(0f, 0f, -90f);
layoutRotator.eulerAngles = new Vector3(0f,0f,90f);
myGrid.cellSize = new Vector2(Screen.currentResolution.height, Screen.currentResolution.width);
}
else
{
myCamera.transform.eulerAngles = new Vector3(0f, 0f, 0f);
layoutRotator.eulerAngles = new Vector3(0f, 0f, 0f);
myGrid.cellSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
}
}
}
}
[2]: /storage/temp/127100-tate-mode.zip
Hi, sorry for my slow reply, and thanks for the thorough explanation!
I tried this out and it works pretty well for the most part. The only issues I really had were that my game view doesn't seem to be the same aspect ratio when it's in TATE mode but I think that's a separate problem to do with the way I've hard-coded my camera's orthographic size value.
So, thanks! This works! :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612181415im_/https://answers.unity.com/themes/thub/images/avi.jpg)