0

I have 2 audio 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);

}
Steven
  • 166,672
  • 24
  • 332
  • 435

2 Answers2

0

Add a variable in your code of type "GameObject".

Create a "particle system" in: "Create" -> "Particle System". Configure it the way you want.

Drag it to one "Prefab".

In the Unity editor drag your prefab into your "GameObject".

Add the line of code:

Instantiate (MyGameObject, this.transform.position, this.transform.rotation);

This line of code instantiate the "GameObject" in the world.

In his "prefab" particle mark: "Play On Awake".

So when you instantiate your particle in the world, it will give "Play" automatically.

Following this step-by-step ... you get what you want.

I hope this helps!

Nuno Duarte
  • 926
  • 7
  • 4
0

Lets take GameObject A & GameObject B

  1. A & B - should have a collider
  2. A || B - anyone should have a rigidbody attached to it.
  3. implement OnCollisionEnter() in A (or) B script.
  4. When collision triggers get the instance of the particleSystem and implement

    EG: particleInstance.Play(); it will start play the particle system.

    Thanks.

suku
  • 217
  • 3
  • 13