UI ingame messages in Unity3D

It’s time to start our new year and this second one will be even better. What I’m saying! This year is going to be 10 times better; it’s going to be awesome!

My first post this year is a new chapter for the Unity3D UI series and it’s our 50th post! In this one we are setting up some things for the final post, attaching a new canvas to a game object that shows up only when the player is near it. Also give a read to some of our old posts if you get lost at some point.

Let’s go, this is an easy one!


unity UI message ingame

Behold the might monolith!

Adding all components

Our first step is adding all the objects we are going to need. Lest do a list for this:

  • Some 3D object. In my case I’ve created a cube, placed somewhere in the map and scaled it a bit. Mine is renamed as “monolith”.
  • A new UI->Canvas object. Set the render mode of this canvas to World Space like we did before here. Then move and transform it to a place near the 3D object.
  • Add some UI->text. This one must be a child of the canvas.
  • An empty GameObject to wrap everything. Mine is called “monolith_group”.
object hierarchy

new objects added to hierarchy

Hide the message


the mighty monolith!

the mighty monolith!

Let’s create some scripts to hide the canvas to show it again only if the player is near the 3D object. This is useful to display UI objects only when they are really needed.

Create a new script under the script folder and name it as you want.  Then we can code it as follows:


Attach it to the 3D object, in my case the “monolith” and drag the canvas to be hidden to the public variable in the inspector.

configure script from the inspector

configure script from the inspector

Face the text!

Now we have a problem.

text problem

text problem


If we try to read the message from other angle, the message still face the front, and it’s not possible to read it from the back, but we can fix it quickly with some more code!. Add the highlighted line to the update function:


Here is an example of the final result (it may take a while to load):


final example

final example

Here is the project if someone want to test it : DOWNLOAD

Here is the complete list of chapters of this Unity3d canvas series where you can find the entire process:

Hope to see you again for another awesome year and another 50 posts! In some days the last chapter of the Unity UI series.


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.