在运行时更改屏幕方向
2 分
请在世界设置中设置默认显示的屏幕方向。

- 方向:选择屏幕的方向。
- 垂直
- 水平
以下是一个示例代码,用于在运行时更改屏幕方向。
仅支持两种屏幕方向:纵向和横向。
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { Button } from 'UnityEngine.UI';
import { Screen, ScreenOrientation } from "UnityEngine";
export default class ChangeOrientation extends ZepetoScriptBehaviour {
public orientationBtn: Button;
Start() {
// 当按钮被点击时
this.orientationBtn.onClick.AddListener(() => {
if(Screen.orientation == ScreenOrientation.Landscape)
{
// 设置屏幕方向为纵向
Screen.orientation = ScreenOrientation.Portrait;
}
else
{
// 设置屏幕方向为横向
Screen.orientation = ScreenOrientation.Landscape;
}
});
}
}👍 提示
- 默认UI(主页按钮、聊天按钮)和虚拟按键在更改屏幕方向时自动支持横向-纵向切换。
- 如果您在内容中提供其他自定义UI,您需要响应方向的变化。