通过c#unity缩​​放时,帆布图像变成隐形

发布于 2025-02-10 20:06:10 字数 225 浏览 1 评论 0原文

我试图制作一个类似口袋妖怪的游戏,并试图从图像中制作出HealthBar并缩放绿色,但是当我通过C#缩放它时,它会使

我的代码不可见:

[SerializeField] GameObject health;

private void Start()
{
    health.transform.localScale = new Vector2(0.5f, 1f);
}

im trying to make a pokemon-like game and trying to make the healthbar out of images and scaling a green one, but when i scale it through c# it turns invisible

my code:

[SerializeField] GameObject health;

private void Start()
{
    health.transform.localScale = new Vector2(0.5f, 1f);
}

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

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

发布评论

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

评论(1

皇甫轩 2025-02-17 20:06:10

当您缩放一些内容时,请确保在所有三个维度上正确缩放它。 transform.localscalevector3,这意味着,如果您使用vector2来定义它,Unity将假设Z-Component是0 。例如,即使您仅在XY系统中查看z方向上,即使3D对象在z方向上没有任何比例时,它们也会立即消失。

private void Start()
{
    health.transform.localScale = new Vector3(0.5f, 1f, 1f);
}

更改您的代码应该解决问题!如果不是这样,那么我认为您消失的游戏对象不会与您的缩放相关。

我希望这会有所帮助!

When you scale something, make sure you scale it properly in all 3 dimensions. transform.localScale is a Vector3, which means that if you use a Vector2 to define it, Unity will assume that the z-component is 0. Depending on what kind of object you are scaling exactly, this can lead to very different results. For example 3D objects will disappear immediately when they dont have any scale in the z-direction, even when you only view them in the xy-system.

private void Start()
{
    health.transform.localScale = new Vector3(0.5f, 1f, 1f);
}

Changing your code like this should fix the issue! If it's not that, then I don't think your disappearing game object is tied to your scaling.

I hope this helps!

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