Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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:
    32
    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:
    26,897
    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:
    32
    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
unityunity