I’m wondering if there is a good way to add dozens of sprites into my scene. There are some effects I want to create for key moments in my game that would basically revolve around having dozens of sprites spew forth out of an object in my scene.
Honestly, my first thought was that I should utilize a particle system. But I’m getting a bit overwhelmed with the options for particles and having a hard time figuring out how to create the effects I’m looking for. I’m not sure how to set up a material that would look like a regular sprite in my game, and I’m not sure how to get them moving in the direction I really want.
I suppose it is the best option, but I’m wondering if there might be another solution worth considering.
I could create what I want using game objects with actual sprite renderers, and it wouldn’t be too hard for me to implement. But the problem there is that each sprite would need a rigidbody2D so I could adjust its velocity with the script I would write. And spawning dozens of objects each with its own rigidbody might be taxing on some weaker systems; it just doesn’t sound like an efficient way to run things.
So maybe instead I could write a script to move the objects manually (since I don’t need collision or gravity anyway) but I don’t know of any way to move an object without a rigidbody short of directly setting a specific position in the world. If my movement is simple enough a script could just add a number to its position in world space each frame, but honestly I want to give these things a vector, and if I have to make the full vector calculations within a script each frame, it quickly becomes more efficient to just use a ridigbody, does it not?
But maybe there is some other method I haven’t considered, or maybe one of the ones I have considered doesn’t work like I thought. At any rate, I’m just curious what methods there are to animating dozens of sprites in my scene. How would you go about doing that?
You can easily turn your spites into material and make them a particle.
Anyway, if you have the Transform.position of the game object you can turn it into an emitter by instantiating your sprites at that location. You can set offset variables and randomize it so the images don’t spawn at the same place, plus make it look exactly like a particle system.
That’s a thought, although it only works if I don’t need the individual sprites to move very much once they are spawned. Worth considering though.
Okay, I’ve been trying to use Unity’s particle system again to try to get it to work the way I want, and I’ve run into a huge problem: layers.
I can’t get seem to control what order the particles get rendered in within my 2D layers. By default they are appearing in front of my background tilemap, but I can’t get them to appear in front of anything else.
Is there a way to control that? If not, then using particles is completely useless in a 2D game, except as a background effect.
Also I can’t figure out how to get them to fade out instead of just disappearing.
You could create a Layer Mask, let’s say you have a layer for Player, BackGround, and Foreground. You want your particles to be part of the foreground so you create a script with just this code: