Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Does ParticleSystem.Emit() absolutely have to be a void?

Discussion in 'Scripting' started by Le-Capitaine, Sep 11, 2014.

  1. Le-Capitaine

    Le-Capitaine

    Joined:
    Jan 23, 2014
    Posts:
    33
    I'm wondering this because I'm trying to get a particle-based shmup to work and nothing I can come up with comes close to a workaround. So I got to thinking, and one thought led to another, and now all I can think about is just how nice it would be if Emit(particle) returned the emitted particle. So I'm asking this in earnest: is there some sort of limitation that prevents it from doing so?

    Alternately, here's the code I'm trying to use if something obvious is flying over my head again.

    Code (CSharp):
    1.  
    2.   public Bullet Fire (Vector3 pos, Vector3 vel, bool localised = false) {
    3.     Bullet bullet = new Bullet();
    4.     bullet.bullet = new ParticleSystem.Particle();
    5.     bullet.bullet.color = particleSystem.startColor;
    6.     bullet.bullet.position = pos;
    7.     bullet.bullet.velocity = vel.normalized * speed;
    8.     bullet.bullet.size = particleSystem.startSize;
    9.     bullet.bullet.lifetime = (range / speed) / 60;
    10.     bullet.localised = localised;
    11.    
    12.     particleSystem.Emit (bullet.bullet);
    13.     bullets.Add (bullet);
    14.     return bullet;
    15.     }
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well for a start the number of particles isn't guaranteed to be 1. It could be thousands.
     
  3. Le-Capitaine

    Le-Capitaine

    Joined:
    Jan 23, 2014
    Posts:
    33
    For reference, I'm specifically referring to Emit (particle), which I believe emits one single particle, as opposed to Emit (int) which emits the specified number.

    edit: Okay, I just tried the second variant of Emit with fixed parameters -- the particle just isn't displayed at all. This might not be supposed to happen. Do particle systems have a maximum range past which particles aren't displayed anymore?
     
    Last edited: Sep 11, 2014