Move Camera towards Object

Hello everyone…

I just want my camera to move towards my player.

For that i tried :

gameObject.transform.localPosition = Vector3.MoveTowards( gameObject.transform.localPosition ,target.transform.localPosition , 2);

But i just want to move my camera on x-z axis. Y position should not be changed.

Which method shall i use ?

Thanks…

Just make a new Vector3 and only give it the x and z values of the target

 gameObject.transform.localPosition = Vector3.MoveTowards( gameObject.transform.localPosition , new Vector3(target.transform.localPosition.x,0f, target.transform.localPosition.z), 2);

or

 gameObject.transform.localPosition = Vector3.MoveTowards( gameObject.transform.localPosition , new Vector3(target.transform.localPosition.x,gameObject.transform.localPosition.y, target.transform.localPosition.z), 2);