Search Unity

How to resize an object with distance?

Discussion in 'Scripting' started by polan31, Jan 19, 2019.

  1. polan31

    polan31

    Joined:
    Nov 20, 2017
    Posts:
    149
    I would like my object to decrease by a certain amount along with the distance it will overcome. How to do it?

    I would also like to stop decreasing after reaching a certain size. How to do it?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    What do you mean by "distance it will overcome"?

    You can use Vector3.Distance() to get the distance between two positions. And you can set transform.localScale to transform.lossyScale to adjust the size of the object. You can use Mathf.Min() to ensure the x/y/z values in your scale don't exceed a certain amount.