martin36 martin36 - 9 months ago 45
C# Question

Relation between bounds.extents and trasform.localScale

I am using the

to represent the radius of a sprite in Unity. In my simulation I am changing the size of the sprite using
. When I want to spawn new sprites I want to spawn them so that the radius won't exceed my ground (represented as a plane). Thus I am making sure that the new sprite is not spawned within a range of
to the edge of the plane. But when the sprites reaches their maximum radius they exceed the edge of the plane. So my question is, what is the relation between

Answer Source

You have to make sure that the radius you allow the sprites to be placed in is less than the extents of the plane and the half the size of the sprite. because when you place the sprite on the edge of the radius, the center of it is on the borders of the plane, so half of it is outside it. Did I understand the problem correctly? As for the relation, the bounds.extents describes half the size of the sprite in units, while transform.localscale is the scale relative to the object's parent's scale. It is also an indication of the current size compared to the original size of the sprite, it doesn't indicate the size in units.

So assuming the parent's scale is 1:

bounds.extents = (original bounds.extents) * transform.localScale