- Home /
How do I destroy a gameobject after 5 seconds
I have this shoot script:
var projectile : Rigidbody;
var speed = 20;
function Update()
{
if( Input.GetButton( "Fire1" ) ) {
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
}
}
And I want the bullets to go away after 5 seconds.
Thanks
Comment
You tagged this "fps" "gun" "shooting" and titled it "Shooting script question".. yet the thing you are asking is essentially "how do I destroy a gameobject after 5 seconds".. magic google time.. http://lmgtfy.com/?q=destroy+gameobject+after+time
Sorry to be rude, but you really need to formulate your question more carefully. Good questions get good answers.
Best Answer
Answer by fafase · Feb 16, 2013 at 09:32 PM
Look at the Destroy function:
Destroy(objReference, timerInSeconds);
Your answer
Follow this Question
Related Questions
Bullet Collision Issues 1 Answer
Need help... Start Button no longer working!!!!! 0 Answers
Projectile Firing/Gun script 1 Answer
FPS Shoooting Problem 1 Answer
Problems with a shooting script 1 Answer