通过c#unity缩放时,帆布图像变成隐形
我试图制作一个类似口袋妖怪的游戏,并试图从图像中制作出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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
当您缩放一些内容时,请确保在所有三个维度上正确缩放它。
transform.localscale
是vector3
,这意味着,如果您使用vector2
来定义它,Unity将假设Z-Component是0 。例如,即使您仅在XY系统中查看z方向上,即使3D对象在z方向上没有任何比例时,它们也会立即消失。更改您的代码应该解决问题!如果不是这样,那么我认为您消失的游戏对象不会与您的缩放相关。
我希望这会有所帮助!
When you scale something, make sure you scale it properly in all 3 dimensions.
transform.localScale
is aVector3
, which means that if you use aVector2
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.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!