- Home /
How to make a floating text over an object that always faces the player?
I just want to have a floating text saying "Ammo" that hovers over a game object (a cube), that fallows the player like so that it is always facing it (I'm using the FPScontroller so maybe to making it look in the direction of the camera would work? I don't know, I'm really stuck and any help is much appreciated!
Comment
Best Answer
Answer by Skaster87 · Oct 15, 2017 at 05:42 AM
Here's an example class to get you started, Attach it to the Ammo Text canvas.
using UnityEngine;
public class AmmoUI: MonoBehaviour {
Camera cameraToLookAt;
// Use this for initialization
void Start()
{
cameraToLookAt = Camera.main;
}
// Update is called once per frame
void LateUpdate()
{
transform.LookAt(cameraToLookAt.transform);
transform.rotation = Quaternion.LookRotation(cameraToLookAt.transform.forward);
}
}
Nice! I had the same issue, and I was missing the
transform.rotation = Quaternion.LookRotation(cameraToLookAt.transform.forward);
However, I had to add it on the Text GO in the canvas for it to work, rather than on the canvas itself. Did missed something ?