Having a 3D text appear in the middle of the screen without using GUI (C#)

Hi all,

For my game, I want to provide some text blocks with information. Because I’m going to use it with the Oculus Rift, I can’t use GUI, so instead of using Canvas with Text children, I’m using 3D texts. For readability, I’m trying to get the text (when this is activated) to appear in the middle of the screen, no matter where the camera turns – like you’re using Screen Space - Overlay with a Canvas.

So far, I’ve found a script to attach to the 3D Text GameObject, which tracks the position of the camera (see code below). However, this isn’t quite what I’m looking for as the text is still not stationary in the middle of the screen. I’ve tried using the same way of coding for tracking the camera rotation, but to no avail.

Is there anyone who could help me out? I’d greatly appreciate it!

public class LookAtText : MonoBehaviour {
	public Camera cameraToLookAt;
	void Start() 
	void Update() 
		Vector3 v = cameraToLookAt.transform.position - transform.position;

		v.x = v.z = 0.0f;

		transform.LookAt(cameraToLookAt.transform.position - v ); 

		transform.Rotate (0, 180, 0);

Hey, what you can do is put the text as a child of one of the cameras (left or right), set its position to (0,0,0) and then use local position to put the text as far as you want from the camera. In this way, it will always follow the movement of the camera … look at this tutorial, you could adapt your way to it: Oculus Rift DK2 - Unity Tutorial: Reticle - YouTube

Looks like you’re just starting with positioning and rotating objects. Putting something in front of the camera, or facing the camera, is no different than putting something in front/facing the player, or a cube… . Reading through the basics should make various solution to this obvious.

As kdrwl writes, an easy way is to use local position. In the Editor, child an object to something and play with position (which automatically counts as localPosition, even though it doesn’t say) to get a feel for it (same with rotation.) In code: myText.parent=someCamera; myText.localPosition=new Vector3(0,0,10);. Since we all know Z is forward, this puts you 10 units along the camera’s blue(Z) arrow. Then myText.LookAt(someCamera); aims directly at it.

Can also use world positioning, involving someCamera.forward*10;. It appears your last line is part of the trick “face the exact way as something, then spin around to face it.” Whole thing is: myText.rotation=someCamera.rotation; myText.Rotate(0,180.0);. But don’t mix methods. There are a few ways to do it, none of them very long, but it’s easy to use 1/2 of method A and 1/2 of method B, and get junk.