Camera transformation upon a pressing a key

Hello Devs,

When I press a key, I want the camera to move to the target gameobject. I am trying make a UI menu where when you press the key it goes to another section of the menu. In order to translate the camera the code I am using is

void trans()
	 transform.Translate(-Time.deltaTime*10, Time.deltaTime*10, 0, Space.World);

I want to halt it when it reaches that position.

Problem :

The camera translates but as the key press is for only a single frame it does not go beyond it. I would like the translation to be locked down to a particular x and y so as that the required gameobject is within screen. Devs, thanks.

Consider using Vector3.MoveTowards.

// Assume target is a transform to move to (when pressed a key etc).
// Assume UpdatePosition is called every frame.
void UpdatePosition() 
    if (!target)

    transform.position = Vector3.MoveTowards(transform.position, 
                                             Time.deltaTime * 10.0f);
    if (transform.position == target.position) 
        target = null;
        // reached target