Game rotation when turning physical device

When I turn my ipod touch I can see black borders rotate around, how can I make my game rotate with it just so that its the correct way around to play?

I have tried various methods on the forums but they dont seem to work.

I only need to support both portrait views.

I’d like to know this as well. Come to think of it, is there any instance at all in a Unity game where the black borders would be a good thing?

Try this:

	void Start()
	{
		// kill the dang keyboard frame
		iPhoneKeyboard.autorotateToPortrait = false;
		iPhoneKeyboard.autorotateToPortraitUpsideDown = false;
		iPhoneKeyboard.autorotateToLandscapeRight = false;
		iPhoneKeyboard.autorotateToLandscapeLeft = false;
        }

But then, the keyboard might appears in the wrong orientation if you call iPhoneKeyboard.Open.

I am trying to support both landscape orientations and when I disable the autorotate, the keyboard does not appear correctly.

Same problem here: I do not want the ugly black frame - but I do want the keyboard to display correctly no matter what the orientation is. I’d say this is a bug - either in Unity or in iOS.

In the Unity scripting reference, it says:

See also ScriptingReference: iPhoneKeyboard

So, when you are using the keyboard but don’t want the ugly black-frame rotation it seems there’s currently no way to get both done; so having the black border is obviously less disturbing as having the keyboard show up with wrong orientation basically makes it useless (probably Apple would even reject a game that does this).

Originally, I thought I could “trick the system” by simply switching autorotate on before displaying the keyboard (or even before displaying screens that need the keyboard) - but unfortunately, that only fixes it when the player switches screen orientation again … so that also doesn’t make a lot of sense.

To answer the original question (which is much easier than getting rid of the nasty border without disabling proper usage of the keyboard):

Do something like this (one possible way is keeping currentOrientation as member variable and then checking whether it has changed on Update and change Screen.orientation in those cases - so watch out, this code is really just meant to give you an idea, it’s not copy’n’paste-proof :wink: ):

        DeviceOrientation currentOrientation = Input.deviceOrientation;

        switch (currentOrientation) {
            case DeviceOrientation.LandscapeLeft:
                Screen.orientation = ScreenOrientation.LandscapeLeft;
                break;
            case DeviceOrientation.LandscapeRight:
                Screen.orientation = ScreenOrientation.LandscapeRight;
                break;
            case DeviceOrientation.Portrait:
                Screen.orientation = ScreenOrientation.Portrait;
                break;
            case DeviceOrientation.PortraitUpsideDown:
                Screen.orientation = ScreenOrientation.PortraitUpsideDown;
                break;
        }

Of course, there’s also ways to rotate the camera smoothly (switching Screen.orientation “switches” to the new rotation - it doesn’t smoothly rotate). However, I don’t think you’ll manage to get the rotation synced with the ugly black frame.