How to make camera move in only one direction ?

I want to make it such that it only moves in positive y direction as the player moves forward like in games like color switch and amazing bricks

This is the script I am using currently if follows the player in both the positive and negative y directions.

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {

    public PlayerController thePlayer;

    private Vector3 lastPlayerPosition;
    private float distanceToMove;

	// Use this for initialization
	void Start () {
        thePlayer = FindObjectOfType<PlayerController>();
        lastPlayerPosition = thePlayer.transform.position;
	}
	
	// Update is called once per frame
	void Update ()
    {
        distanceToMove = thePlayer.transform.position.y - lastPlayerPosition.y;

        transform.position = new Vector3(transform.position.x, transform.position.y + distanceToMove, transform.position.z);

        lastPlayerPosition = thePlayer.transform.position;
	}
}

So if the player moves in the negative y direction, what should the camera do? Not move at all? If that’s what you want, just add an if to your Update function around the last two statements, like this:

if (distanceToMove > 0)
{
    transform.position = new Vector3(transform.position.x, transform.position.y + distanceToMove, transform.position.z);
     
    lastPlayerPosition = thePlayer.transform.position;
}