Have a game where you've to shoot somethings and when you hit the GameObject I've should play. I've tried with Instantiate but I can keep shooting even if the gameobject is destroyed. What should I do in order to fix it?

 public GameObject particlesystem;

 void Start () {
    particlesystem= GameObject.Find("Effect");

 void Hit(){
 Instantiate(particlesystem, transform.position, transform.rotation);

This is how I handle it now, but as I wrote earlier I can keep activating the particle system.


2 Answers 2


Particle System

Get your particle system in code and use public methods like Play() and Stop().

Just as an example of use:

if (Time.time > 50) {

I think that the best way to do it is, instead of

particlesystem= GameObject.Find("Effect");

assign the prefab in the unity GUI (in the script field)

In addition, when you want to play the effect you should have to do it this way

var gO = Instantiate(particlesystem, transform.position, transform.rotation);
Destroy(gO, seconds);

I don't remember if var is a gameobject or an object type, but with var it should work.

Edit: if you have to destroy the game object (which are you shooting) call destroy(gameobject) too


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .