How can I make my camera immovable on the Y axis?

I am a newbie to Unity and I was trying to make somewhat of an infinite runner to improve my stance. It’s a game where a ball tries to stay on platforms. I made a camera follow script (c#) and I not sure how to stop the camera from following the ball when it falls of the platforms.

	public GameObject player;
	private Vector3 offset;

	void Start()
	{
		offset = transform.position - player.transform.position;
	}

	void Update()
	{
			transform.position = player.transform.position + offset;
	}
}

Vector3 pos= player.transform.position + offset;
transform.position=new Vector3(pos.x,transform.position.y,pos.z);