- Home /
Answer by LukeAntConroy · Feb 11, 2013 at 09:25 PM
Firstly you need to import the package.
Go to the Assets
Click on import Package Particles.
This is some code I wrote it may be able to help you.
using UnityEngine; using System.Collections;
public class Trap : MonoBehaviour {
//public ParticleEmitter PE_BlastBomb;
public ParticleEmitter PE_EnemyExplosionEffect;
public ParticleEmitter PE_BlastBomb;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyUp(KeyCode.E))
{
FireExplosion();
}
}
public void FireExplosion()
{
ParticleEmitter PE_effect = (ParticleEmitter)Instantiate(PE_BlastBomb,transform.position,Quaternion.identity);
PE_effect.Emit();
Vector3 V3_explosionPos = transform.position;
Collider[] C_collider = Physics.OverlapSphere(V3_explosionPos,10.0f);
foreach(Collider C_hit in C_collider)
{
if(!C_hit)
{
continue;
}
if(C_hit.rigidbody)
{
C_hit.rigidbody.AddExplosionForce(300.0f,V3_explosionPos,10.0f);
}
}
Destroy(gameObject);
}
}
Answer by Grug16 · Feb 11, 2013 at 09:57 PM
The simplest answer, conceptually, is to get a prefab of an explosion (I'm partial to the Detonator package on the asset store) and instantiate it just before destroying the cube.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating a Asteroid health script 5 Answers
If health <5 Then Explode 2 Answers
explosion instaniate not destroyed 1 Answer
Can i destroy this cube? Logic?? 1 Answer