- Home /
Complex object scaling
Hi! So I've got a problem with scaling object to some length. Object I want to scale got : -Rect Transform(so it has height) - Box Collider 2D Exactly it's laser that's made of 3 different objects but it doesn't matter here. I'd like to scale it to height of empty space between space ship that shots it and any object it collides. I tried to make it like this:
float newH = laser.position.y - collidingObject.transform.position.y;
// laser position is set on its top
float scaleY = newH / laser.GetComponent<RectTransform>().rect.height;
//length we want to get divided by length of laser
Then I just put new scale to laser but it doesn't seem to work well. How to scale Object with its height to length we want to get?
Comment