How to follow an object from camera in forward direction but not in right direction?

I want to make a game which is similar to Running with friends. I am changing slots perfectly. But the problem is that camera should not move horizontally when the player changes slots. My code is working in single direction. But when the player turns to another platform it is giving strange results.

If any one know the solution please post your answer

You can use transform.LookAt(Transform target,Vector3.forward) on any one of Camera scripts. to make your camera to follow an object in forward direction.