im trying to make change in my recttransform when the screen of the android became portrait or landscape, but the code just read the screenrotation portrait, the other never work. i dont know why.
if (Screen.orientation == ScreenOrientation.Portrait)
{
rectTransform.anchoredPosition = new Vector2(0, 50);
rectTransform.sizeDelta = new Vector2(800, 100);
}
if(Screen.orientation == ScreenOrientation.Landscape)
{
rectTransform.anchoredPosition = new Vector2(0, 33);
rectTransform.sizeDelta = new Vector2(800, 75);
}
}
}
The API you're using ( Screen.orientation
) is for setting different orientation behaviors. If you'd like to read the current value, you want Input.deviceOrientation
and check against theDeviceOrientation
object it returns:
if (Input.deviceOrientation == DeviceOrientation.Portrait ||
Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
{
}
else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft ||
Input.deviceOrientation == DeviceOrientation.LandscapeRight)
{
}
Also, to rule this out (just in case): Make sure in the ProjectSettings > Player inspector, with Android selected, under " Resolution and Presentation ", make sure your application is allowing the device to handle rotations with " Default Orientation " set to " Auto Rotation " and " Allowed Orientations for Auto Rotation " contains what you'd want it to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.