H
H
Herman Coffman2021-05-17 17:06:29
Unity
Herman Coffman, 2021-05-17 17:06:29

How to stretch an object in Unity?

I stretch the object between 2 transforms:

desroySprite.transform.localPosition = new Vector3(transform.position.x, minY.transform.localPosition.y, transform.position.z);
    desroySprite.transform.localScale = new Vector3(transform.position.x, maxY.transform.localScale.y, transform.position.z);

But something doesn't work. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kachan, 2021-05-17
@MANAB

1. Assuming that the Pivot is in the geometric center, you calculate the average position between 2 transforms

desroySprite.transform.position = 0.5*transform1.position + 0.5*transform2.position;

2. Assuming that with scale = 1 the size is equal to N units, you calculate the scale
desroySprite.transform.localScale = desroySprite.transform.position / N;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question