Sri Krishna Paritala
Sri Krishna Paritala

Reputation: 617

Stretch a sprite between two points during runtime in Unity

I have a UnityEngine.Sprite and need it to be stretched between two points.

How can I achieve this at runtime using Unity?

Upvotes: 0

Views: 2394

Answers (1)

OMGtechy
OMGtechy

Reputation: 8230

  1. Put the sprite in the middle of the two points.

If you want a runtime stretching effect

  1. Change the sprites scale until the bounds match those of the points. You can use Lerp to help achieve this affect over a specified period of time.

If you want it to fill the space instantly

  1. Calculate how much you need to scale by and scale by that amount

Calculating scale

scale = targetSize / realSize;

So, given a space of 1000 x 400 pixels that you wish to fill with an 800 x 600 image...

scale.x = 1000 / 800;
scale.y = 400 / 600;

Upvotes: 1

Related Questions