I’m trying to figure out how I can use text as a particle effect in either the new or old Particle systems in Unity.
I want to use it for indicating damage. ie: An object is hit with 5 units of damage and the particle system spawns a single particle with the text ‘5’ over that game object in the prescribed movement/color/whatever pattern defined for the particle.
Ideally, a texture/material will be used that contains all the characters, rather than an individual texture/material for each character (using variable-width fonts so I can’t guarantee each character has an exact amount of ‘space’ along a row or column in the texture).
I just can’t see how I can tell the particle (via script) to clip out specific piece, or pieces (in the case of numbers with >1 digit) from the material and use it.
Any help would be greatly appreciated. (Perhaps there is a way of doing this via built-in Unity text handling?)
I suppose you could use the UV animation stuff, or Texture Sheet Animation. You can make a page-flip animation of the particle, so you’d have to get the right ‘page’ to show up. Not sure how well that would work.
You don’t wanna just use a dedicated script? Probably simpler than trying to force a PS to do that.
I have created the damage numbers system for my game, it sounds like it’s something you need but I have not used any particle systems. My idea was:
Create a “number” prefab which is a small UI panel with text field in it, and a script which accepts color, and a target Transform object
Script for the number object will recalculate the target Transform’s world position into 2D canvas position using RectTransformUtility each frame, and position itself on the new calculated position
On an object which takes damage:
Instantiate a new empty gameobject simply for it’s transform. In it’s update, move the transform away from object slowly. Alternatively, use a rigidbodied prefab to have it behave something like Borderland’s system if you wish.
On function which deals damage:
Call the damage on the object (to trigger it’s ‘target’ prefab spawning)
Instantiate the damage prefab, set it’s damage number and color, and assign the Transform to follow to the target’s prefab transform.
Don’t forget to have a lifetime for the numbers before they’re gone, and if you plan on having a lot of damage numbers on screen, consider pooling the damage prefab numbers.
I'd really look into either using a GUITexture (in screen-space) or TextMesh with a billboarding script on it (in world space). http://unifycommunity.com/wiki/index.php?title=LookAtCameraYonly
– DaveAHow would I make this work in a separate script? What would be the best way to do go about doing that? Thanks.
– davethewave7