Wednesday, January 21, 2015

Unity: Prevent 3D Text from always appearing on top

The default shader used by 3D Text make it always appear on top, which is not desirable, for example, when the 3D text attached to a game character go behind a wall or build, the text will still be showing. There is already a well-explained tutorial (see the link below) that shows how to incorporate a shader for 3D text to get around this issue:

http://wiki.unity3d.com/index.php?title=3DText

The problem is for a newbie like me, I had a difficult time to figure out how to generate a font texture for the font material mentioned in that tutorial, on which to apply the shader. Therefore, this tutorial documents on how i managed to find the solution. Firstly, go to unity asset store:

https://www.assetstore.unity3d.com/

Key in "font" in the search box, download and import a free font asset from the asset store into your project, for example, the following one will do:

https://www.assetstore.unity3d.com/en/#!/content/4235

After the font asset has been imported, select the font asset folder under "Assets" in the project panel, and select the font you would like to generate the font texture and material. In the inspector panel, change the "Character" field from dynamic to Unicode, click the gear button at the upper-right of the inspector panel and select "Create Editable Copy", as shown in the figure below:




This will generate the font texture and font material at the same time, as shown in the figure below:




 Remember to change the "shader" property of the font material in the inspector panel to "GUI/3D Text", Now you can change the font material and font in the 3D text component to match with the font material and font you just created. Below is the result of applying the shader in a project i am working on:






2 comments: