Hi there I am just working on a simple game. When the player hits a game object it explodes and sends particles out. The simple script is below.
using UnityEngine;
using System.Collections;
public class DestroyCubesBlue : MonoBehaviour
{
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Safecube")
{
Destroy(col.gameObject);
SpecialEffectsHelperBlue.Instance.Explosion (transform.position);
}
}
}
I want the particles to collide with enemy cubes and destroy it The enemy cube just as the other cube that exploded has a box collider and a rigid body attached to it and a mesh renderer (The normal cube you can create in unity).
How I call the particles when the cube gets destroyed is using a another simple script.
using UnityEngine;
/// <summary>
/// Creating instance of particles from code with no effort
/// </summary>
public class SpecialEffectsHelperBlue : MonoBehaviour
{
/// <summary>
/// Singleton
/// </summary>
public static SpecialEffectsHelperBlue Instance;
public ParticleSystem BlueExplosion;
void Awake()
{
// Register the singleton
if (Instance != null)
{
Debug.LogError("Multiple instances of SpecialEffectsHelper!");
}
Instance = this;
}
/// <summary>
/// Create an explosion at the given location
/// </summary>
/// <param name="position"></param>
public void Explosion(Vector3 position)
{
//
instantiate(BlueExplosion, position);
}
/// <summary>
/// Instantiate a Particle system from prefab
/// </summary>
/// <param name="prefab"></param>
/// <returns></returns>
private ParticleSystem instantiate(ParticleSystem prefab, Vector3 position)
{
ParticleSystem newParticleSystem = Instantiate(
prefab,
position,
Quaternion.identity
) as ParticleSystem;
// Make sure it will be destroyed
Destroy(
newParticleSystem.gameObject,
newParticleSystem.startLifetime
);
return newParticleSystem;
}
}
All I want to do is the particles that come out destroy the enemy like a shockwave Thank you. I believe I have to use OnParticleCollision?