iOS Screen Orientation

What’s the current accepted/correct way to have your Unity game change orientation when the player rotates their device? Has it changed recently?

I start out in landscape-left and would like to also allow landscape-right, but NOT the portrait orientations.

I had some old code in place to do it but I think it’s all deprecated now.

This is what I was using on the previous game I released. No idea whether it was “correct” or not, but it worked. I attached this to its own GameObject I think.

function Awake() {
    DontDestroyOnLoad(this); 
}

function Start() {
    iPhoneKeyboard.autorotateToPortrait = true; 
    iPhoneKeyboard.autorotateToPortraitUpsideDown = true; 
    iPhoneKeyboard.autorotateToLandscapeRight = false; 
    iPhoneKeyboard.autorotateToLandscapeLeft = false; 
}

function Update() { 
    if (Input.deviceOrientation == DeviceOrientation.Portrait) 
        iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Portrait;
    if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown) 
        iPhoneSettings.screenOrientation = iPhoneScreenOrientation.PortraitUpsideDown;        
}

If you get Unity 3.4, it comes with built in orientation. I removed all of my orientation scripts from my game and switched to Unity’s, it works very well. The option is in “player settings”. I have it set to Landscape only.