- Home /
Screen.orientation absolutely fails to respond
so i am making this game for iOS, and in it I display pictures on the screen,
in landscape mode i want them to look like this
X X X
in portrait i want them to look like this
X
X
X
i realized that since the player would be rotating their device the objects wouldn't even need to move! (YAY) all i needed to do was to rotate them so they remain facing the same way each time.
so i am trying to make the objects rotate to fit each orientation
but for some reason, when i open the game in my Xcode iOS simulator, there are no effects. none, zilch. what do you think is going on?
heres the code, it is attached to my three game objects
if(Screen.orientation == ScreenOrientation.LandscapeRight){
Destroy(gameObject);
transform.rotation.eulerAngles = Vector3(0,0,90);
}
if(Screen.orientation == ScreenOrientation.PortraitUpsideDown){
transform.rotation.eulerAngles = Vector3(0,0,180);
}
if(Screen.orientation == ScreenOrientation.LandscapeLeft){
transform.rotation.eulerAngles = Vector3(0,0,270);
}
if(Screen.orientation == ScreenOrientation.Portrait){
transform.rotation.eulerAngles = Vector3(0,0,0);
}
thanks for all help!
Are you changing your Screen.orientation value somewhere?
Because (unless maybe ScreenOrientation.AutoRotate is set) it does not so on his own.
You have to check the Input.deviceOrientation (your phone's orientation as detected by the sensors) variable to see which DeviceOrientation state de phone indicates and change the Screen.orientation variable to the corresponding wanted value.
Input.deviceOrientation : indicates how your device is oriented
Screen.orientation : indicates the current orientation used for the GUI (which on its own has no direct link to the device orientation)
if(Input.deviceOrientation == DeviceOrientation.LandscapeRight){
I changed them all to that, they still don't work. i am EXTRE$$anonymous$$ELY confused i get this error message
Operator '==' cannot be used with a left hand side of type 'UnityEngine.ScreenOrientation' and a right hand side of type 'UnityEngine.DeviceOrientation'.
okay, freaky, i copied the example code from the documentation, and pasted it into my code. now it works. I checked and re-re-rechecked what i had typed and what the documentation said. It is exactly the same!!!!!!!
well it works now, but do you think it was something else in the code that threw it off, or is this a bug i should report to unity?
i mean what i had before was
if(Input.deviceOrientation == DeviceOrientation.LandscapeRight){
now i have
if(Input.deviceOrientation == DeviceOrientation.LandscapeRight){
this seems pretty funky to me