- Home /
when changing size of gameobject bounds do not change
Currently i am changing the size of a game object via:
g.transform.localScale=new Vector2(width,height);
and this correctly changes the width and height by a factor of width and height. This seems to work great, until one has to work with the following piece of code which is designed to place another game object next to the one previously in the list (subs):
g.transform.position = new Vector3 ((subs[subs.Count-1].renderer.bounds.max.x + g.renderer.bounds.extents.x),transform.position.y,transform.position.z);
in this code subs is a list of gameobjects, and g is the game object to be moved. This code works fine without scaling, but with it it doesn't. I believe the reason for this is that the bounds are not being updated. Can someone please tell me the best way to rescale a gameobject and also update the bounds?
Answer by kboudai · Sep 26, 2014 at 01:13 AM
float actualSize = g.renderer.bounds.x * g.transform.localScale.x;
but the docs say of renderer.bounds: "This is the axis-aligned bounding box fully enclosing the object in world space."
note the "world space". shouldn't this mean he should NOT have to scale by the localScale?
Your answer
Follow this Question
Related Questions
How to get the position that is closest to a target within a given radius 0 Answers
How to calculate projectile range 2 Answers
Object instantiates on top of the previous object 2 Answers
Checking to see if a position is occupied by a GameObject 2 Answers
How to make cubes between 2 point and stick them together? 0 Answers