Hi, I’d like to create a (2D) particle system where the particles would be a number or a word.
I’d like the option to change the text via code as I spawn a new particle system, but I am trying to avoid manually creating a bunch of diffuse bitmaps with just numbers and words, as doing it via Text and code seems like more optimized option…?
I guess I am looking for a way to convert a UI Text or similar into a Material, or use the Text as an Opacity map for the material, which I can apply to the particle system.
Is it possible, any suggestions?
Thanks to your question, I’ve created my first Unity tutorial video.
And the subject is: Particles with Dynamic Text
The idea is to use another camera and a canvas
The second camera renders its own overlay canvas onto a render texture.**
This texture will then be assigned to a material that will be used by the particle system.
Since the material keeps changing when you change the text, the particles are also changed.
Here’s a little screenshot:
Here are the steps:
(This is for advanced users, if you get stuck, watch the video tutorial below)
- Create a new 2d scene (works also on 3d scene but that’s how I did this)
- Create a particle system and set it in front of the camera
- Change particle settings so that particles will be slower and bigger:
Start Speed to 1 and
Min Particle Size to 0.1
Tweak these values to your liking
- Create another camera, let’s call it
- Set it to be orthographic and move it a bit so it will be out of the way
- Create a new Render Texture, call it
- In the
Text Camera set the target texture to be the
- Disable the audio listener on
Text Camera, as you can’t have two of them in a scene.
- Create a canvas, set it to
Screen Space - Camera and select the
text-camera as its camera
- In the canvas create a panel, set its color to black and full opacity (by default it’s half!)
- Add a text object to the panel, let’s leave it with the default name
Text, set its color to white and resize it to fit nicely inside the panel
- Check that in the
Text Camera you can see the text clearly and that it more or less fills the frame
- Create a new material, call it
Text Material and set its shader to one of the particle shaders, I used “Mobile/Particles/Additive”
- Set the texture of the
Text Material to be
- You should now see in the material preview the current text that you entered in the Text object
- Go to the particle system and set the material in the renderer to
which explains everything step by step
Awesome! Thank you so much! Your instructions worked like a charm, and is exactly what I was wanting!