x


How do I make a timer for a grenade?

I am making a grenade and want a timer, so it doesn't explode as soon as it hits the ground. What script is used for this?

more ▼

asked Aug 25 '10 at 03:28 AM

MonkeyAssassin8 gravatar image

MonkeyAssassin8
271 35 38 43

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

3 answers: sort voted first

Take a look at WaitForSeconds. Then, assuming you want the timer to start from when the grenade is thrown, do something like:

  1. Instantiate the grenade
  2. Wait for as many seconds as you want (using the above method)
  3. Play an explosion sound, spawn a particle effect, destroy the gameObject, etc

In future, you should try scripting it yourself and then post if you have problems (that you can't find a solution for by searching). Otherwise you'll usually have your question tagged as 'write-my-code', and generally they're ignored.

more ▼

answered Aug 25 '10 at 05:15 AM

Marowi gravatar image

Marowi
4.9k 4 14 53

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

Well i will be happy to right your code. But this may not work. But go ahead and try it.

function Update ()
{
    yeild WaitForSeconds(5);
    Destroy (gameObject)
}

If this does not work for you search up yeild wait for seconds but this should work. You have to code your own particle emiter though. So you got to do a bit coding yourself too you know.

more ▼

answered May 09 '11 at 09:24 PM

Kashaunzilla gravatar image

Kashaunzilla
34 17 19 28

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

Instantiate the grenade...

Destroy(gameObject, 5);

http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html

Particle Effect the grenade...

more ▼

answered Aug 25 '10 at 04:21 AM

joedrigon gravatar image

joedrigon
231 5 6 13

Your first answer was more correct. He wants the particle effects when the grenade is destroyed. If he does as you've said, the explosion will happen and then 5 seconds later the grenade will disappear.

Aug 25 '10 at 05:11 AM Marowi

Yea, I looked at my first post and didn't think that was the correct way to do it... obv it was lol!

Aug 25 '10 at 11:50 PM joedrigon
(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:

x347
x132
x23

asked: Aug 25 '10 at 03:28 AM

Seen: 1523 times

Last Updated: Aug 25 '10 at 03:49 AM