hello how do i destroy a game object when collided. but how do you destroy the game object slowly not instantly.
3 Answers
3Make an animation of the object being "destroyed" and play it on collision...
function OnCollisionEnter(collision : Collision) {
//Do stuff.
}
It really depends on how you want it to "destroy slowly" If you want it to ease in to the ground, just enable a script that auto-moves the object down using transform/translate.
destroy: http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html
Oncollider: http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html
OnTrigger: http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html
function OnCollisionEnter(other : Collision){
Destroy(other.gameObject, 4);//The number means the seconds before kill or destroy the object
}
Note: you can also use OnCollisionStay,OnCollisionExit or OnTriggerStay,OnTriggerExit. Another thing is that If you dont want to destroy the object only disappear you may use SetActiveRecursively(http://unity3d.com/support/documentation/ScriptReference/GameObject.SetActiveRecursively.html)
THIS IS VERY EASY TO DO MAN. USE WAIT FOR SECONDS HERE IS A EXAMPLE SCRIPT I MADE.
function OnTriggerEnter ()
{
yield WaitForSeconds();
Destroy(gameObject);
}
If you still need help with wait for seconds go google it up.
One question. WHY CAPS?
– FLASHDENMARK