Unity-代码控制横竖屏
public void ChangeScreenCh() { if ("切换到`在这里插入代码片`横屏") { Screen.orientation = ScreenOrientation.LandscapeLeft; Screen.orientation = ScreenOrientation.AutoRotation; Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = true; Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; } else//竖屏 { Screen.orientation = ScreenOrientation.Portrait; canvasScalerTemp.referenceResolution = new Vector2(standard_height, standard_width); //canvasScalerTemp.matchWidthOrHeight = 1; BG.localEulerAngles = Vector3.forward * 90; } }
另外的设置方法:
竖屏 Screen.orientation = ScreenOrientation.Portrait; Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = true; Screen.autorotateToLandscapeLeft = false; Screen.autorotateToLandscapeRight = false; 横屏 Screen.orientation = ScreenOrientation.AutoRotation; Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = true;

浙公网安备 33010602011771号