using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Update is called once per frame
void Update()
{
GetDeviceRotation();
}
void GetDeviceRotation()
{
// 获取当前设备的屏幕旋转角度
ScreenOrientation currentOrientation = Screen.orientation;
int angle = 0;
switch (currentOrientation)
{
case ScreenOrientation.Portrait:
angle = 0;
break;
case ScreenOrientation.PortraitUpsideDown:
angle = 180;
break;
case ScreenOrientation.LandscapeLeft:
angle = -90;
break;
case ScreenOrientation.LandscapeRight:
angle = 90;
break;
}
Debug.Log("设备旋转角度:" + angle);
}
}
获取当前设备的屏幕旋转角度,并根据不同的旋转模式映射为对应的角度值
于 2023-12-14 19:39:45 首次发布