- Home /
Particle System Texture Sheet Animation - One of each Frame?
I don't know if this is possible or not; I've been messing with the particle system properties for a while and can't get it to perform how I'd like.
I have a texture sheet containing 3 rows of 4 sprites. The particle system is set to fire 1 burst of 4 sprites. I'd like the particle system to select a random row from the texture sheet and spawn exactly one of each sprite in that row for the burst emission. Sadly, the property for Start Frame only lets me pick a random sprite within constraints, so I can't guarantee that the same sprite will be duplicated within a burst.
I'm not massively familiar with scripting particle systems, but if this is a viable solution I'll gladly attempt to implement it.
Answer by ifurkend · Jan 11, 2018 at 05:03 PM
You should rotate your sprite sheet texture by 90 degree, use 3 by 4 tile division and specify 1 row instead of random row. Finally duplicate this particle system 3 times with different sheet row. Unity should be able to batch the drawcalls of all 4 particle systems.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class nameYourScriptHere : MonoBehaviour {
public ParticleSystem[] ps;
float column;
void OnEnable () {
var tsam = ps[0].textureSheetAnimation;
column = (float)(int)Random.Range(0, tsam.numTilesX - 1)/tsam.numTilesX;
for (int i = 0; i < ps.Length; i++) {
tsam = ps[i].textureSheetAnimation;
tsam.frameOverTimeMultiplier = column;
}
}
}
Thanks for the reply! I think this is heading closer to what I want, but I'm not sure it's quite perfect. I'd like each particle emission to emit 4 sprites of the same set/column. The idea is to have different shattering effects when a ship is destroyed.
I've made a quick image to show what I'm after; I want each particle burst to emit exactly one of each sprite within a single green column. The red boxes show an example of what the particle system could spawn using your method, if this makes more sense
It does need a script (check my updated answer) for this occasion even though I feel that it's more productive to not handle it with particle system because you only want 4 particles emitted from the whole setup each time.
Thank you, that's working exactly as I'd like now.
If you have a better method for this then I'm keen to learn and explore other avenues. But you've helped me out a lot so no worries if not, and thank you for your time :)
Your answer
Follow this Question
Related Questions
Particle system does not re-emit until Start Lifetime elapsed 4 Answers
Bad quality of the sprite in Unity 0 Answers
Particle system, unaffected by attached sprite 1 Answer
Anti aliasing with sprites 0 Answers
compress photos on import 0 Answers