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;

 

posted @ 2022-09-16 14:52  jiaxin2015  阅读(397)  评论(0)    收藏  举报