- Home /
How to have animation when orientation changes
I want to have my iPhone app only display only landscape left and landscape right. However, when the app changes orientation I want it to show the standard rotation animation that iOS applications do when they rotate. In noticed that the Penelope sample application supports this kind of animation, but I haven't been able to get it working for mine. Is there something special that needs to be done? I using the following script, but instead of animating to the new orientation, the app will immediately redraw in the new orientation:
using UnityEngine; using System.Collections;
public class OrientationScript : MonoBehaviour {
void Start () { // see http://answers.unity3d.com/questions/21700/unity-iphone-black-rect-when-i-turn-the-iphone.html iPhoneKeyboard.autorotateToPortrait = false; iPhoneKeyboard.autorotateToPortraitUpsideDown = false; iPhoneKeyboard.autorotateToLandscapeRight = false; iPhoneKeyboard.autorotateToLandscapeLeft = false; }
void Update () { if ((Input.deviceOrientation == DeviceOrientation.LandscapeLeft) && (Screen.orientation != ScreenOrientation.LandscapeLeft)) {
Screen.orientation = ScreenOrientation.LandscapeLeft; } else if ((Input.deviceOrientation == DeviceOrientation.LandscapeRight) && (Screen.orientation != ScreenOrientation.LandscapeRight)) { Screen.orientation = ScreenOrientation.LandscapeRight; } } }
Answer by thomasw · Jun 22, 2011 at 06:23 AM
It appears that this is a feature currently not supported by iOS Unity 3.3.
http://feedback.unity3d.com/forums/15792-unity/suggestions/1236209-proper-native-orientation-handling-for-unity-ipho http://feedback.unity3d.com/forums/15793-unity-iphone/suggestions/1194061-standard-iphone-autorotation
edit:
This is a feature of Unity 3.4. See the discussion here to see how to get this working: http://answers.unity3d.com/questions/46492/ios-smooth-auto-rotation-of-orientation.html