Referencing Objects and disabling Scripts on them instantly

Hey guys! I have a problem…

I have platforms in my game. I use object pooling to spawn them in front of the player.
Now the platforms are moving and what i want is when player jumps the platform will stop moving, that way he can time it and when he feels like the platform is in good position he will jump and the platform will “wait” until he lands and then leaves.

I don’t know how to reference the platform in front of the player in the script and then disable the script responsible for the movement.

What i tried to do is put a empty game object on the player and put a trigger on it. Then i placed it on the platform in front of the player. Since the platforms have the same distance between it would always touch the platform in front of him. After that i tried to use OnTriggerEnter Stay and Exit but none of them seem to work. OnTriggerExit worked the best but there was a little delay in disabling the script. I need it to be instant it would be awesome if it could respond to the MouseClick Input function that makes the player jump.

Though I am unsure, the reason your triggers are not responding may be due to the fact that it is a child of a gameObject using a CharacterController. Whatever the case –

There are many options to achieve what you are looking for:

OPTION 1:
Check out Physics.Raycast:

It will basically check an imaginary line from a starting point towards a direction and return an object. Then you can use the object to access the platform script .gameObject.GetComponent<“NAME OF PLATFORM SCRIPT”>().enabled = false. Then simply re-enable the script through another raycast or whenever the play jumps.

OPTION 2:
Put box colliders as triggers on each platform instead of the player. Have the trigger check if the collider is the player and enable/disable on OnTriggerEnter/OnTriggerExit

Option 3:
Similar to raycast, you can use Physics.OverlapSphere:

This would essentially create your own “Trigger” in a sense.

Check out the complete Physics documentation Unity - Scripting API: Physics for other ways to achieve your goal.