- Home /
Script for Vanishing Platforms
Hello,
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?
Answer by stingman · Apr 29, 2012 at 01:12 AM
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
Thanks for the feedback, it clarified things and allowed me to complete my script. I ended up going with your suggestion of using an empty gameobject, didn't realize that a collider could be placed upon it. Thanks again.
Answer by devilkkw · Apr 29, 2012 at 01:05 AM
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.
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How can I set the order of destruction of game objects? 1 Answer
How to import the object from server to unity 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers