How do I know that the object has reached its goal?

I have an object which, when I press a key, should move to the target, how can I find out in the script that the object has reached its goal?

Use lerp and when the time value reaches 1, you have reached your target:

float timeCount = 0.0f;

void Update(){

object.transform.position = Vector3.Lerp(object.transform.position, targetPos, timeCount);

if(timeCount >= 1.0f){
//target reached
}
timeCount = timeCount + Time.deltaTime;

}

hm i’d use a Vector3.Distance for ± accurate equation of the target => if(Vector3.Distance(objectPosition,targetPosition) <0.01f)

or

if(objectPos == TargetPos) but sometimes the target position is not the same as object position, so you use the first code

@Trild123787898 i agree with @dan_wipf 's answer but an other option would be to simply add a trigger and check the on trigger function

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Target")
        {
//ur action goes here
        }
    
    }