The Orientation is always Portrait during runtime

Hello,

I want to test Orientation in Unity, so I created simple project, and chose Iphone Wide (480x320)

And I configured with iOS setting as below:

Ok, then I added C# script to MainCamera component with content:

using UnityEngine;
using System.Collections;

public class ScreenSolution : MonoBehaviour {

	// Use this for initialization
	void Start () {
		//Screen.orientation = ScreenOrientation.LandscapeRight;
		Debug.Log ("or = " + Screen.orientation);

		if (Screen.orientation == ScreenOrientation.Portrait)
			Debug.Log ("current orientation = " + Screen.orientation);

		else if (Screen.orientation == ScreenOrientation.Landscape)
			Debug.Log ("Landscape");
		else if (Screen.orientation == ScreenOrientation.Portrait)
			Debug.Log ("Portrait");

	}
	
	// Update is called once per frame
	void Update () {

	}
}

But when I run my project, results from console is always Portrait:

or = Portrait
current orientation = Portrait

I configured Resolution is Iphone Wide (480x320) , so I think result should be Landscape, right ?

Please advise me about this .

Thank you very much.

Hi @tle94,

You’re getting Portrait because you’re running the game inside the editor, which defaults to Portrait.
Try making a simple UI with just one Text called txtOrientation, link it in the inspector with a public variable and use this in Update():

txtOrientation.text = Screen.orientation.ToString();

Try it out on your device and it should tell you what the orientation is.
If you wish to know the device’s true orientation, you can use Input.deviceOrientation.

Cheers!

Thank you so much, blackdragonbe

“Try it out on your device” , you mean I should export my project to iOS/Android devices for testing ?

@tle94

Yes exactly, it’s the only way of getting the correct readings.

Cheers!

1 Like