I recently added some 3D text to my scene to follow the top of the player. This was done so the Player’s name wouldn’t appear when he was behind a building.
I got that to successfully work, but the only problem I’m having now that I moved it into 3D space, is that the text doesn’t keep the same size relative to the screen size. The further you go away, the the harder it is to notice the player’s name. Anyone know how to keep the size consistent relative to the screen?
Obviously this is an old thread, but just thought I would help anybody else looking for an answer. The first thing you must do is pick a default font size and relative default distance, like so:
You could set the scale of the object according to the distance from the camera. You will have to adjust the values/settings but basically just use Vector3.Distance on the camera transform and the 3d text transform.
public class Example : MonoBehaviour {
public Transform cameraTransform;
void Example() {
if (other) {
float dist = Vector3.Distance(cameraTransform.position, transform.position);
print("Distance to other: " + dist);
Vector3 newScale = transform.localScale;
// adjust local scale based on distance
transform.localScale = newScale;
}
}
}