x


How would I make an object disappear after a set amount of time?

As the title says; I'm trying to make a gun script, I have the gun shooting as I wanted, but the cloned rigidbodies stick around, clogging up the game. How would I make them disappear after a set amount of time?

more ▼

asked Mar 02 '11 at 05:51 PM

Ozy gravatar image

Ozy
18 4 6 8

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

var lifeTime = 1.0;

function Awake () { Destroy (gameObject, lifeTime); }

Here you go. Next time use the search function because that has been answered several times.

more ▼

answered Mar 02 '11 at 06:00 PM

Joshua gravatar image

Joshua
6.4k 19 25 70

Thanks, I didn't have time today to do a thorough search, but next time I will search a bit further.

Mar 02 '11 at 07:45 PM Ozy

Why the -1? :s confused

Mar 02 '11 at 10:58 PM Joshua

why did this answer get a -1? im upvoting it

Mar 21 '11 at 04:36 PM networkZombie
(comments are locked)
10|3000 characters needed characters left
var destroyTime : Int; // This is the time in seconds
function Start(){

yield WaitForSeconds(destroyTime);
Destroy(gameObject);
}
// attach the script to the game object that is supposed to disappear. Good Luck =)
more ▼

answered Mar 02 '11 at 06:01 PM

networkZombie gravatar image

networkZombie
244 9 11 20

Well, it works, and I thank you for that, but it destroys the prefab and/or the gun instead of the cloned prefab which renders my little gun thing useless.

Mar 03 '11 at 02:35 PM Ozy

make sure its attached to the bullet and not to the gun.

Mar 15 '11 at 01:49 AM networkZombie

I want my bullet to disappear after 5 seconds, this is instant, Any help?

Apr 30 at 11:42 PM fjcym11
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3721
x3317
x1780
x1089
x106

asked: Mar 02 '11 at 05:51 PM

Seen: 2355 times

Last Updated: Apr 30 at 11:42 PM