创造你的世界
用户界面
在运行时更改屏幕方向
2 分
请在世界设置中设置默认显示的屏幕方向。 方向:选择屏幕的方向。 垂直 水平 以下是一个示例代码,用于在运行时更改屏幕方向。 仅支持两种屏幕方向:纵向和横向。 changeorientation 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,您需要响应方向的变化。