Prevent Unity 3D Text from Always Appearing on Top while Maintaining Rich-Text Support

The TextMesh component in Unity has an annoyance which causes the text that it displays be rendered always on top. This is useful if you want your GUI elements to always appear on top but if you want to have a 3D text attached to a 3D object, this creates the weirdest results!

There’s already an entry in Unity’s wiki page detailing how the issue can be worked around using a custom shader. This YouTube video shows the application of the mentioned method (it’s quite useful even though the guy is speaking Russian!). Also, if you are not sure how a texture can be built using a font, follow the steps described in this awesome blog post.

The issue with the above method is that it messes with the rich text support of TextMesh. Essentially, all text will be rendered with the specified color of the created material. I found a better custom shader in the Unity 3D forum! This solved my z-depth issues.

Orient a Transform to a Specific Direction in Unity 3D

If you are too lazy to do the math to orient an object to a specific direction, this tip is useful for your.

The Transform objects in unity have the Forward, Up and Right properties. You probably don’t know that they are not only accessors but also mutators! You can simply assign a direction vector to an object’s Forward direction and the object will face that direction:

This can be handy sometimes, especially when you want to use the Kinect sensor inside the game. If the players arm direction signifies the orientation of something (eg. a sword), this tip saves you some time.