2

I'm building a shaped particle system (a galaxy) using a Unity Sprite component and the various emitter modules, where the sprites are static and last forever (100000 seconds)...

    public ParticleSystem particles_galaxy;
        ParticleSystem.EmissionModule galaxy_emmitter;
        ParticleSystem.TextureSheetAnimationModule  galaxy_textureAnim;
        ParticleSystem.EmitParams galaxy_params;  

I procedurally add particles, emitting them with a position and orientation and colour etc. I want to select which sprite to draw from a group of sprites.

I have assigned several sprites to the TextureSheetAnimationModule in the Inspector, and I can set them in the editor to change what's drawn. I can change the sprite used for the particles in code using galaxy_textureAnim.startFrame to specify a frame number, but this affects all sprites and doesn't change for each sprite as added.

Here I'm trying to add ten spiralling sprites with a random texture selected from two options:

    for(int n = 0; n < 10; n++){
        particleRadialDistance = n*0.1f;
        particleRadialPosition = n*0.1f;
        placement.y = Mathf.Lerp(0.35f, 0.5f, particleRadialDistance);
        placement.x = particleRadialPosition*Mathf.PI*2;
        galaxy_params.position = class_utilities.PositionFromPolar(placement);
        galaxy_params.rotation = 180+Mathf.Lerp(0,-360,particleRadialPosition);
        galaxy_params.startSize = Mathf.Lerp(1f, 2f, particleRadialDistance);
        galaxy_textureAnim.startFrame = Random.Range(0,2);
        particles_galaxy.Emit(galaxy_params, 1);
    }

How do I change the frame/sprite number for each sprite?

David Coombes
  • 317
  • 1
  • 13

1 Answers1

-1

Try this:

galaxy_textureAnim.startFrame = new ParticleSystem.MinMaxCurve(0, 2);
Edival
  • 420
  • 6
  • 9
  • 1
    Thanks. That allows a random selection, but can I change it to select a frame per sprite? I've tried if(particleRadialPosition < 0.5f){ galaxy_textureAnim.startFrame = new ParticleSystem.MinMaxCurve(0,0); }else{ galaxy_textureAnim.startFrame = new ParticleSystem.MinMaxCurve(1,1); } With MinMaxCurve's with a single constant or linear ranges, but the animation frames are applied to all sprites. I need to be able to specify which animation frame for which particle. – David Coombes Feb 20 '19 at 10:07