I was wondering what is the best way to create a script that will make a platform disappear after a character controller collides with it, then leaves the platform. My intention is to have the a character jump onto the platform and when the character jumps off the platform will be destroyed. I have found a set of scripts in scripting reference called OnCollisionExit but have yet to find a way to utilize it for my needs. Is this the right approach or is there other pieces of script I should be looking into to better accomplish my needs?
function OnCollisionExit(collisionInfo : Collision) {
//make sure collider is a player,in this case check the transform name,also use Tag
if (collisionInfo.transform.name=="Player") Destroy (gameObject);//destroy immediately,use Destroy (gameObject,3); for destroy after 3 sec.
}
OnCollisionExit only works if you are working with non-kinematic rigidbodies and since you are using a character controller I suggest using OnControllerColliderHit if you want to go this route. There are several ways of doing this but I think an even easier way is to create a prefab of your jump platform and use OnTriggerExit instead. Just use an empty game object for the trigger and place it on top of your platform. When the player leaves the trigger code in 1 line to destroy the platform. simple and effective. But if you want to use oncontrollercollider hit you can do that as well. Just a lot more code to do the same thing