Moving Platforms and Collision

I have a bit of a largely complicated problem, but I have tried to simply it down to a much easier to understand concept.

Suppose that you are a player and there is a moving platform that goes between two ledges that you can walk on. Simple enough, however, you can’t walk off the ledge when the platform isn’t there. The platform has to be touching the ledge in order for the player to be able to walk off of the ledge, and onto the platform.

Essentially the question is about localized collision which can turn on and off. How could I make it so that the collision (let’s just take a BoxCollider2D as an example in this context) disappears when the platform touches the ledge, then reappear when it’s gone away from the ledge?

Thanks!

Edit: MS Paint example of Concept!

When the platform touches against one of the big orange squares, their respective green lines (collision) turn off and allow the player to pass through.

Something like this should work on your ledge box collider object :

function OnTriggerEnter (other : Collider) {
        
    if (other.gameObject.tag == "Platform_Trigger") {
        collider.enabled = false;
    }
}

function OnTriggerExit (other : Collider) {
    
    if (other.gameObject.tag == "Platform_Trigger") {
        collider.enabled = true;
    }
}

You must parent/place a trigger onto your platform and tag it as “Platform_Trigger” for this to work.