Running code when player moves over

So, I have written a basic script to make an infinite platform but I want it only to spawn a new platform once the player passes over half way of the previous. I also want the platforms no longer visible to the camera to be removed. Any suggestions on how to proceed? Also, preferably don’t just write (a) new script(s) for me to use!

`
using UnityEngine;
using System.Collections;

public class PlatformGen : MonoBehaviour {

    public GameObject Platform;
    private Vector3 OriginalPos;

	void Start () {

        OriginalPos = transform.position;

	}

	void SpawnPlatform () {

        Vector3 NewPos = OriginalPos + new Vector3(-25f, 0f);
        Instantiate(Platform, NewPos, Quaternion.identity);
        OriginalPos = NewPos;

	}

}

`

A simple way to do this is to create a trigger on your platforms. When your character collides with it, call the PlatformGen.SpawnPlatform() platform. Unfortunately, you will have to put a script on the Platform prefab to detect the collisions. Don’t forget to add a reference of your PlatformGen in the platform script.

Triggers tutorial : https://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers

Doc ref : Unity - Scripting API: Collider.OnTriggerEnter(Collider)

public class Platform : MonoBehaviour {
 
     public PlatformGen PlatformGen;
 
     void OnTriggerEnter(Collider collider)
     { 
         PlatformGen.SpawnPlatform() ; 
     }     
 }

 void SpawnPlatform ()
 { 
     Vector3 NewPos = OriginalPos + new Vector3(-25f, 0f);
     GameObject newPlatform = (GameObject) Instantiate(Platform, NewPos, Quaternion.identity);
     newPlatform.GetComponent<Platform>().PlatformGen = this ;
     OriginalPos = NewPos; 
 }