0

I have a particle system defined in my game objects. When I call Play it plays (it plays for 5 seconds by design). when I call Play again nothing happens. I tried to call Stop and Clear before recalling Play but that didn't help.

Can particle systems play more than once?

My code is in this method, which is called when a button is clicked.

public void PlayEffect() 
{ 
    for (int i=0;i<3;i++) 
    { 
        NextItemEffectsP[i].Stop(); 
        NextItemEffectsP[i].Clear(); 
        NextItemEffectsP[i].Play(); 
    } 
} 

NextItemEffectsP is an array that contains particles that I populate in the editor

Nick Udell
  • 2,420
  • 5
  • 44
  • 83
  • Please post some code so that we'll be able to see how to help you. Also, what language is your code in? – krillgar May 03 '14 at 22:41
  • This code in this method. Tthe method called when a button clicked. public void PlayEffect() { for (int i=0;i<3;i++) { NextItemEffectsP[i].Stop(); NextItemEffectsP[i].Clear(); NextItemEffectsP[i].Play(); } } NextItemEffectsP is an array that contains particles that I populate in the editor – user2130415 May 04 '14 at 03:02
  • I found the issue. The duration of the particle is 2 second. if I call play after 2 second nothing happen. Should I create new instance everytime I need to start a particle after the 2 second? how can I kn ow when the particle finish work so I can destroy it. – user2130415 May 04 '14 at 14:14

1 Answers1

0

You should rework how your bullet works. Have some code on the bullet Prefab to control when it gets destroyed.

private float fuse = 1.0;
private float selfDestructTimer;

void Awake() {
    // Time.time will give you the current time.
    selfDestructTimer = Time.time + fuse;
}

void Update() {
    if (selfDestructTimer > 0.0 && selfDestructTimer < Time.time) {
        // gameObject refers to the current object
        Destroy(gameObject);
    }
}

Then with that control set up, you'll always just create new bullets whenever the fire button is pressed.

krillgar
  • 12,596
  • 6
  • 50
  • 86