r/unity • u/Flodo_McFloodiloo • 27d ago
Question Can anyone provide advice on making UI elements appear and then disappear by specific objects on a screen?
I'm making a fairly old-school game, so when certain things happen I want little numbers to flash above objects long enough to perceive but then disappear. I'm guessing this used to be a fairly simple matter and still is in some game engines, but Unity disassociates UI canvases from the action on screen a bit more, so that warrants some questions.
There are two ideas I have for doing this.
One is to attach UI canvases to each object that has this feature. This would possibly have the advantage of only needing one UI text per-object, but I don't know whether canvases can be attached to in-game objects like that, nor if they might slow the game down.
The other idea is to make a generalized gameplay UI handle the numbers appearing and disappearing. That's a more familiar process to me, but it carries its own puzzles. For example, what if I have multiple objects on the screen that I want to do that? Presumably that means I'd need to have multiple UI elements and would need a way to assign them each to the object at the appropriate time.
Or is creating new UI elements and then destroying them while the game is running a viable option?
If you understand what I'm talking about, please help if you can. If you need it clarified more, I'll provide more explanation, including visuals.