Adding a single colored 2d panel in a 3d game
So, here is what I want to achieve:
There are a couple of players, and each of them should have a name, an icon and some other information following the players model as a name tag. The name tag shall have a single colored background, that can be easily changed via script and should be resizable depending on the length of the players name. The name tag should be a child of the 3d model of the player.
Here's what I tried:
UI Panel - this has pretty much everything I need, but it can only be rendered on a Canvas. Since each tag should be a child of the player, this would mean a canvas for each player and I think that there are some major performance drawbacks if I do this.
Sprite with white image - works good, but you can't resize it properly. You can scale it, but this distorts all child elements like text, icons, etc
Plane - pretty much the same as the Sprite solution, and it feels... "dirty". This probably isn't what these planes are for.
My Question: Is there a simple way to add a 2d object with a recttransform component, that is completly filled with a single color, no matter how you resize it? Basically just like a UI panel that works outside of a canvas.
Thank you for your time.
Jonas
Answer by Zodiarc · Nov 04, 2016 at 01:37 PM
Did you try the world space canvas? You can do the "parenting" by a simple script which adjusts the world position of the panels to the player positions with some offset. This way you would have only 1 canvas.
This might just do the trick for me. I will give it a try and tell you how it went.
Still, is there no solution to the general problem? It would be nice if you could resize sprites just like you can do with panels. Or use panels without a canvas. Well, maybe in Unity 6... :)
Answer by tanoshimi · Nov 04, 2016 at 01:45 PM
"I think that there are some major performance drawbacks if I do this" -> What makes you think this? Have you tried profiling? If you've only got a couple of players there really should be no problem here - I have 30+ canvases in a scene with no performance hit (just remember to disable the graphic raycaster component if you don't need it)
I think I read somewhere in a tutorial or forum post, that this is costly in terms of performance, but maybe this was because of the raycaster component. Does your game with 30+ Canvases run on mobile? Because the game I'm working on will be ported to a mobile version soon.
It's not a mobile game, but I have no reason to believe it would be a huge problem on mobile.
Your answer
Follow this Question
Related Questions
IMAGE AND SPRITE SETTINGS 0 Answers
Scale all things inside UI canvas 0 Answers
How do I draw line on panels and canvas? 0 Answers
How to fix blur sprites and text in UI 0 Answers
Attach UI elements to screen corners 1 Answer