代码直接设置 Screen.orientation 的值即可
竖屏: Screen.orientation = ScreenOrientation.Portrait;
横屏:Screen.orientation = ScreenOrientation.Landscape;
但是如果是跳转网页或者打开网页,需要先打开网页在设置横竖,不然可能是设置失败或者页面大小不到。最好等一帧
是否需要自动旋转横屏或者竖屏的方向
// 可以自动旋转为竖屏或者横屏
Screen.autorotateToPortrait = true;
// 横屏时自动可以自动旋转为左为底
Screen.autorotateToLandscapeLeft = true;
// 横屏时自动可以自动旋转为右为底
Screen.autorotateToLandscapeRight = true;