Is it possible to create Text string particles?
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?
Answer by LiloE · Mar 02, 2017 at 06:58 PM
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:
I setStart Speed
to 1 andMin Particle Size
to 0.1
Tweak these values to your likingCreate another camera, let's call it
Text Camera
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
Text Renderer
In the
Text Camera
set the target texture to be theText Renderer
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 thetext-camera
as its cameraIn 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 panelCheck that in the
Text Camera
you can see the text clearly and that it more or less fills the frameCreate 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 beText Renderer
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
Text Material
And finally, the tutorial video
which explains everything step by step
This is pretty awesome, but what if you want to randomize the text for each particle?
Really useful!
A tip for all those who will stumble here. If you wanna get rid of that slight border around the text simply enlarge the panel from step 10 to go beyond canvas boundary.
Answer by Tronotrond · Mar 05, 2017 at 02:17 AM
Awesome! Thank you so much! Your instructions worked like a charm, and is exactly what I was wanting! :D
Please don't add comments as answers, that's what the "Add comment" buttons are for.