Getting width of 2d object in unity 3d

后端 未结 2 832
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 09:36

I\'m using the new 2d tools in Unity3d, and I have a game object with a 2d polygonal collider attached to it. I just want to understand how to get the width of this object! Why

2条回答
  •  盖世英雄少女心
    2021-02-06 10:15

    According to this post, looks like 2D colliders indeed should have the missing bounds variable, and it will be made available in a future release.

    So looks like for now you'll have to make do with a workaround. One could be to add a Sprite Renderer component to your GameObject, add a dummy image to it and set it disabled so it's never visible. Then you can use gameObject.renderer.bounds to get the sprite bounds.

提交回复
热议问题