Unity解决:动态切换横竖屏

动态切换横竖屏

/// 
/// 切换为横屏
/// 
private void SetOrientationLandscape()
{
    //设置横屏
    Screen.orientation = ScreenOrientation.Landscape;
    //设置横屏画布标准分辨率,保证UI横竖屏一致
    scaler.referenceResolution = new Vector2(1920, 1080);
    //这个match比例一般情况是这样,可根据项目情况设置
    scaler.matchWidthOrHeight = 1;
}

/// 
/// 切换为竖屏
/// 
public void SetOrientationPortrait()
{
    //设置竖屏
    Screen.orientation = ScreenOrientation.Portrait;
    //设置竖屏画布标准分辨率
    scaler.referenceResolution = new Vector2(1080, 1920);
    scaler.matchWidthOrHeight = 0;
}

你可能感兴趣的:(Unity,C#,unity,游戏引擎)