I want to move an object toward a target and scale it from 1 toward zero ...

As I mentioned in the title, I want to move and scale an object with same speed.

For instance, Object ‘A’'s been moved toward a target for 10 sec.

In the same time, the object ‘A’ should be scaled from 1 toward zero for 10 sec.

So, I did like this.

const float m_fMoveSpeed = 100.0f;
float m_fScaleSpeed = 0.0f;

// Set a target object
public void SetTarget(Transform target)
    {        
        Vector3 com1 = transform.localPosition;
        Vector3 com2 = target.localPosition;
        float ret = Vector3.Distance(com1, com2);

        m_fScaleSpeed = ret / m_fMoveSpeed;

        m_pTarget = target;    
    }

void Update () {
        if (m_pTarget != null)
        {
            
            transform.localPosition = Vector3.MoveTowards(transform.localPosition, m_pTarget.localPosition, m_fMoveSpeed * Time.deltaTime);

            Vector3 scale = transform.localScale;
            //scale = Vector3.MoveTowards(scale, new Vector3(0.01f, 0.01f, 1f), m_fScaleSpeed * Time.deltaTime);
            scale.x -= m_fScaleSpeed * Time.deltaTime;
            scale.y -= m_fScaleSpeed * Time.deltaTime;
            transform.localScale = scale;

            if (scale.x == 0.01f)
            {
                m_pTarget = null;
            }
        }
	}

It doesn’t work. move speed is about twice faster than scaling speed.

(i am not good at even basic math XD)

Anyone helps me. Thanks.

Doesn’t the idea you had and commented out not work?

This is how I solved a similar problem with a coroutine:

//change the size of the unit
function SetLocalScale()
{
	
    var newSize = Vector3(transform.localScale.x * 1.5f, transform.localScale.y * 1.5f, transform.localScale.z * 1.5f);

    while (Vector3.Distance(transform.root.localScale, newSize)>0)
    {
        transform.root.localScale = Vector3.MoveTowards(transform.root.localScale, newSize, Time.deltaTime*10);
        yield;
    }
}