|
How would I go about writing a script which when a grenade prefab which I have, collides with anything in my world it would destroy itself and give of an explosion which I have made with a particle effect?
(comments are locked)
|
|
It's simple: just use OnCollisionEnter to fire the explosion:
var explosion: GameObject; // drag your explosion prefab here
function OnCollisionEnter(){
var expl = Instantiate(explosion, transform.position, Quaternion.identity);
Destroy(gameObject); // destroy the grenade
Destroy(expl, 3); // delete the explosion after 3 seconds
}
You can add the explosion sound to the explosion prefab - with Play On Awake set (is the default option) it will play automatically when the explosion is created. Thanks Guys
Oct 09 '11 at 10:03 AM
Dreave
oh one other thing when my grenade collides with something the particle effect has a short delay, can you help?
Oct 09 '11 at 10:18 AM
Dreave
As in, is that what you want, or is it doing that already? If there's a delay before the explosion, check your prefab particle effect to make sure that it looks right.
Oct 09 '11 at 10:23 AM
syclamoth
Oh yeah, if you use AutoDestruct on the explosion, it will delete itself- no need to use the 'Destroy(timer)' after instantiation.
Oct 09 '11 at 10:25 AM
syclamoth
Ive figured it now thanks
Oct 09 '11 at 10:27 AM
Dreave
(comments are locked)
|
|
and if the explosion is a particle system, you can check autodestruct (and you may want to check one shot), so there's no need to destroy it manually, and you can be sure that it it run a single animation, and then it will destroy it self
(comments are locked)
|
