# Position Text Mesh above parent transform in world space

I'm making an isometric-ish 2d game in Unity. I want to display text above a sprite during certain conditions. For this, I'm using a TextMesh instantiated as a child of the sprite.

In local space, this obviously means that when I rotate a sprite, its children rotate along with it. From the player's perspective, the label now appears to the side of the sprite, rather than staying above it.

I can always calculate the world space position of the TextMesh during LateUpdate(), but a) that solution requires a designer to know that a script will alter the local transform, and b) things built into Unity have more eyeballs on them, so I'd rather use that.

Is there a mechanism built into Unity such that I can set a child's transform in the inspector to e.g. position.y = 0.4 and have it render 0.4 units above the parent in world space? Edit: Additionally, I want it to follow the parent as it moves, so just calculating once on Instantiate() isn't quite what I want either.

• In the inspector? No. You'd have to write a custom script. Aug 15 '17 at 1:32
• Ah, thanks for the confirmation. Would using UI text to accomplish this work, or is this TextMesh with script approach my best bet? Aug 15 '17 at 3:30
• UI text would probably be just as awkward. Just create a script with a public Vector3 that it uses to update the position of its game object. Aug 15 '17 at 3:43
• Thanks. If you want to post that as an answer, I'd be glad to accept it. Aug 15 '17 at 15:25

Create a MonoBehaviour component script that exposes a public Vector3 that is then used to update the position of the object in WorldSpace instead of local.
• Thanks! I went with code that copies the transform.position to a private member variable on Awake() so that a designer can use the inspector to set the values without the script overwriting them. Aug 15 '17 at 17:48