Search Unity

Particle System "Burst" only once?

Discussion in 'Scripting' started by Plott, Sep 13, 2016.

  1. Plott

    Plott

    Joined:
    May 12, 2014
    Posts:
    94
    Im trying to understand this below. Im adjusting to basically shoot a burst of particles when the player enters a collider. It works fine, but its just a burst and obviously the example given in documentation.

    Code (CSharp):
    1. public class ParticleTrig : MonoBehaviour {
    2.  
    3.     void OnTriggerEnter2D (Collider2D other) {
    4.         if (other.gameObject.tag == "Player") {
    5.  
    6.                 Debug.Log ("Emit");
    7.  
    8.                 ParticleSystem ps = GetComponent<ParticleSystem>();
    9.                 var em = ps.emission;
    10.                 em.enabled = true;
    11.  
    12.                 em.type = ParticleSystemEmissionType.Time;
    13.  
    14.                 em.SetBursts(
    15.                     new ParticleSystem.Burst[]{
    16.                         new ParticleSystem.Burst(1f, 10),
    17.  
    18.  
    19.                     });
    20.         }
    21.     }
    22. }
    So here is the question, under "new ParticleSystem.Burst(1f, 10)," How would I make it only "burst" once?

    Currently when you enter, it shoots 10 particles out at the same time, which is fine, BUT it keeps shooting them every 1f. (Obviously because Burst( has a float _time, and a Short _count)) Thats what leads me to believe it should be a burst, but something else.

    Sorry for the lack of knowledge here, I've been searching all night and can't seem to search the correct word to solve what i want.
     
  2. PeaceLaced

    PeaceLaced

    Joined:
    Jun 2, 2015
    Posts:
    53
    Turn off looping, ParticleSystem.loop = false.
     
    stanko_unity and d2clon like this.
  3. Plott

    Plott

    Joined:
    May 12, 2014
    Posts:
    94
    Thanks for the response, I tried using it within the code above to no avail. the only thing its doing is making the particle system stop completely and not burst once. I added the code into em.SetBursts().

    is that not the place? Im just not understanding whats going on i think.
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You'll probably want to set it earlier with "ps.loop = false;" The whole particle system will loop, the bursts are within the emission module inside the particle system. So if you have one burst, the particle system will loop after each lifetime, and continue playing that single burst. So you set the whole particle system not to loop, not inside "SetBursts".
     
  5. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Try using ParticleSystem.Emit instead.
     
  6. Plott

    Plott

    Joined:
    May 12, 2014
    Posts:
    94
    I finally gave up on looping (it was working, but it wasn't exactly what i wanted.)

    I did more research into .Emit which is a PAIN to figure out.

    http://answers.unity3d.com/questions/1124163/particlesystememitparams-unity-53.html

    Code (CSharp):
    1.     void OnTriggerEnter2D (Collider2D other) {
    2.         if (other.gameObject.tag == "Player") {
    3.  
    4.                 Debug.Log ("Emit");
    5.  
    6.                 ParticleSystem ps = GetComponent<ParticleSystem>();
    7.  
    8.                 ParticleSystem.EmitParams emitOverride = new ParticleSystem.EmitParams();
    9.                   emitOverride.startLifetime = 10f;
    10.                   ps.Emit(emitOverride, 20);
    11.            
    12.                 }
    13.        
    14.         }
    So for anyone who needs a script the emits a particle when the player enters a 2d collider, here you go! Thanks for the help everyone!
     
    stephenkim79 likes this.
  7. Studio22

    Studio22

    Joined:
    Dec 9, 2018
    Posts:
    3
    Thanks bro !