0
\$\begingroup\$

The rect tool in Unity2D (I honestly do not remember if it is present in Unity3D) allows you to scale down/scale up an object in just one direction (what it does is it simultaneously increases/decreases the height of an object in transform.scale and transform.position. I was trying to scale down an object while keeping its position the same using this code (P.S. I took the first four lines of code from here: The Best Way To Generate a Random Float in C#):

       float range = (double)float.MaxValue - (double)float.MinValue;
       float sample = scaleRand.NextDouble();
       float scaled = (sample * range) + float.MinValue;
       float f = (float)scaled;
        if (f > 0.6f)
        {
            f = 0.6f;
        }
            gameObject.localScale = new Vector2(gameObject.lossyScale.x, (gameObject.lossyScale.y - f));

However, this code does not work. So, how can I recreate the effect of using the rect tool in Unity Editor using C#?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.