1
votes

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?

1

1 Answers

-1
votes

Try this:

galaxy_textureAnim.startFrame = new ParticleSystem.MinMaxCurve(0, 2);