I have 2 clips playing when the OnCollisionEnter function kicks in, I would like to also display a particleSystem, at the position where collision occurred.
Here is the code;
private var beenHit : boolean = false;
private var targetRoot : Animation;
var hitSound : AudioClip;
var chitSound : AudioClip;
var resetSound : AudioClip;
var resetTime : float = 3.0;
var dieEffectsPrefab : Transform;
public ParticleSystem DestructionEffect;
function OnCollisionEnter() {
audio.PlayOneShot(chitSound);
audio.PlayOneShot(hitSound);
Debug.Log("HitSomething");
animation.CrossFade ("dying");
Destroy(gameObject,1);
}
If the particle system is already instantiated (e.g. as a child of your object), you can use DestructionEffect.Play()
In your case, I imagine the particle system is not instantiated, so you can simply instantiate it. In this case, if it is set to play on awake, you don’t need to do anything else, otherwise, you call Play() on the instantiated object.
Something like:
ParticleSystem effect = Instantiate( DestructionEffect, transform.position, Quaternion.identity ) as ParticleSystem;
effect.Play(); // Only needed if system is not playOnAwake
Finally, there is also the ParticleSystem.Emit() method, if you want to just emit a few particles.