Instantiate ParticleSystem

Hello, guys.

I made ParticleSystem and set in player script public variable to add the reference to my ParticleSys prefab.

public ParticleSystem expl;

And then in Die() method I would like to make some explosion, but I don’t know how can I Instantiate() this ParticleSys in the current position of player(this script attached to it).

void OnCollisionEnter2D(Collision2D other)
    {
        Instantiate(expl);
        Die();
    }

Please, give me some help :slight_smile:

Instantiate(expl, GameObject.Find("RedBird").transform.position, Quaternion.identity);

It’s work now. But, problem that when it instantiate it moves with camera. How can I make it stay on the spawn position?
Maybe I can spawn it as child of “RedBird” object? But, then new question, how spawn in as child?

Okay, I made it a child and freeze position when Die() is runs. But how can I make after 1 sec(for example) instantiate ParticleS was destroyed?

void OnCollisionEnter2D(Collision2D other)
    {
        GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
        var explosion = Instantiate(expl, GameObject.Find("RedBird").transform.position, Quaternion.identity);
        explosion.transform.parent = gameObject.transform;
        Die();
    }

I tried to make it by Destroy(GameObject.Find(“Explosion”); but nothing happened. :frowning:

Do you want the game object + particle to be destroyed or just the particles?
You could do:

Invoke("MethodName", 1);

Where “MethodName” is a method that destroys whatever you’re looking to destroy (particles, or gameobject + particles) :slight_smile:

I would like to delete only the particle system. I will try your method and after 1 Invoke I will stop invoke :slight_smile:
Thx for help :slight_smile:

I decided not to make Invoke way, because I found, as I think, more easiest way. I made Coroutine and set timer to 3sec and after particle finished her animation I deleted this. It’s work fine with GameObject.Find :slight_smile: Thx for answering this topic :slight_smile:

Cool, a coroutine was another option. Glad ya got it working. :slight_smile:

Yeah, but now I try to learn and solve another problem. If u want you can see my another topic, cause this is only about ParticleSys. I try to learn it, but I can’t find good example how to use it (I talking about another my topic:)

It doesn’t work for me bc I cant add a ps to my public variable, it has to be attached as a component (cant’ be a game obhject) to a game object and that game object isn’t found when I search for a compatible component to add to the public variable (ps).

Ok nvm, dragging and dropping worked for some reason, where it didn’t find it de novo in the file heirarchy.

I tried explose.emission.SetBurst();but VS doesn’t detect the Unity - Scripting API: Burst UnityEngine.ParticleSystemModule module when I using it. It should detect when just UnityEngine as using, right?

Meaning I can’t define a new Burst.

Just edit your original post. Don’t spam in a 5 year old thread you necro’d.