- Home /
Can I change individual particles to different sorting layers?
So I'm making a 2d game and I have a projectile that collides with an opposing player. When this collision occurs it creates a particle system simulating an exploding snowball. Basically, I want particles with a z-position in front of these sprites to render on the same sorting layer with a higher sorting order than those with a z-position behind. I know I can do this for the whole particle system with something like:
particleSystem.renderer.sortingLayerName = "foreground";
particleSystem.renderer.sortingOrder = 2;
where "foreground" is my sorting layer and the sprites are a different sorting order either behind or in front. My question is can I do something similar for individual paricles. Right now I have something like:
void OnCollisionEnter2D(Collision2D collision) {
if (collision.collider == opponent) {
Instantiate(snowPrefab, transform.position, transform.rotation);
Particle[] snowFlakes = snowPrefab.particleSystem.GetParticles;
for (int i=0; i<snowFlakes.Length; i++){
if (snowFlakes[i].position.z < opponent.transform.position.z){
snowFlakes[i].renderer.sortingLayerName = "foreground";
}
}
Object.Destroy(this.gameObject, 0.1f);
}
}
Which doesn't compile as each particle does not have a renderer. Any help would be appreciated.
Hi. Got a same problem. I want to control where each particle is rendering. Did you found a workaround?