根据屏幕尺寸缩放 UI 按钮和图像

发布于 2025-01-16 04:45:20 字数 93 浏览 3 评论 0原文

我正在开发一款统一游戏,我希望能够缩放按钮和 UI 元素以适应不同的屏幕尺寸。请问我该怎么办?我尝试过根据屏幕尺寸进行缩放,但它似乎对我没有帮助。有一个我可以使用的脚本吗?

I ma developing a game for unity and i want to be able to scale my buttons and UI elements to fit different screen sizes. Please how can i go about this? I have tried scale with screen size and it doesn't seem to help me. Is there a script i can use for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2025-01-23 04:45:20

您将需要使用画布缩放器

画布缩放器在 Inspector中,

您只需将此对象附加到画布上,作为 UI 元素的父级,它就会相应地缩放它们。

您还需要确保您的 UI 元素是 正确锚定,以便它们用正确的锚点拉伸 观点。

You will want to use a canvas scaler for this.

Canvas scaler in inspector

You simply attach this object to your canvas parenting your UI elements and it will scale them acordingly.

You will also want to make sure your UI elements are anchored correctly so that they stretch with their correct anchor point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文