0
\$\begingroup\$

I'm having trouble trying to destroy my Instantiated particle system, I can only destroy my gameobject

using UnityEngine;
using System.Collections;

public class meteor_destruction : MonoBehaviour {

public GameObject meteor_d_effect;
public GameObject meteor_explo_effect;
public GameObject meteor_explo2_effect;

public int pointsIncrement = 1;

void OnCollisionEnter2D (Collision2D col)
{

    var effect_explo = Instantiate(meteor_explo_effect, col.gameObject.transform.position, col.transform.rotation);
    var effect_explo2 = Instantiate(meteor_explo2_effect, col.gameObject.transform.position, col.transform.rotation);
    var effect_d = Instantiate(meteor_d_effect, col.gameObject.transform.position, col.transform.rotation);
    Destroy (gameObject);
    Destroy (effect_explo,3);
    Destroy (effect_explo2,3);
    Destroy (effect_d,3);

}

It's generated after the meteor collide, but those 3 particle effects keeps adding inside my Hierarchy panel.

\$\endgroup\$
-1
\$\begingroup\$

Set the collider as a Trigger and use void OnTriggerEnter2d (Collider2D coll).

A Trigger calls only once and does not keep calling the function. On collision enter function will be called multiple times.

\$\endgroup\$
1
  • \$\begingroup\$ This answer is inaccurate. An OnEnter triggers once, regardless. OnTriggerEnter triggers for kinematic colliders, while OnCollisionEnter triggers for non-kinematic colliders. \$\endgroup\$
    – Gnemlock
    Jan 12 '17 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.