Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
kburke's avatar
kburke
Honored Guest
12 years ago

Drawing text directly onto the screen

Hi, I would like to draw some text onto the screen.

I know this is not a best practice, and that text should have a fixed location in the world, instead of moving with the user's head. However, the text I'd like to draw is along the lines of "Get comfortable in your chair and press any button to recenter the screen," and given that the Rift may be in any orientation when a demo is started, it seems like a good practice to fix this to the user's screen.

This seems like it should be fairly simple to implement; I've had success with drawing quads, positioning text in the world, and changing the color of objects. However when I try using OVRGUI.StereoBox(), nothing appears. Another comment on this forum from an Oculus employee references a method called DrawStereoBox but this method results in a compile time error. I copied this snippet of code from a class I found in a Github search.


// using Oculus 0.4.2 SDK
public class TargetScript : MonoBehaviour {
void OnGUI() {
Debug.Log("Drawing Recenter dialog.");
string loading = "LOADING...";
OVRGUI guiHelper = new OVRGUI();
guiHelper.StereoBox(300, 300, 300, 300, ref loading, Color.white);
Debug.Log("Stereo Box should be visible.");
Debug.Log (guiHelper);
}
}


I expect that this will make the words "Loading" appear on screen in front of the user. Instead nothing appears. The debugging information makes it clear that this text is executing.

What am I missing?

I am new to Unity as well as the SDK so if you need to point me to go learn about textures or some other element, please let me know.

3 Replies

Replies have been turned off for this discussion
  • Hi. I had the same problem is you.

    This package has been really good to me:

    viewtopic.php?f=37&t=4944

    Once you download and import the package, create a new script and attach to 'CameraRight' in 'OVRCameraController'

    In you're script do the following:

    public class TargetScript : VRGUI
    {
    public override void OnVRGUI()
    {
    Debug.Log("Drawing Recenter dialog.");
    string loading = "LOADING...";
    GUI.Box(new Rect(300, 300, 300, 300), loading);
    Debug.Log("Stereo Box should be visible.");
    }
    }


    This basically allows you to use the normal GUI functionality, and it does the stereo stuff and corrects it automatically.
    In terms of styling (e.g. text colour), look up any tutorials on GUI Styles and/or GUI Skins. You pass the style as a third parameter in GUI.Box

    i.e.

     GUI.Box(new Rect(300, 300, 300, 300), loading, myGUIStyle); 


    Hope this helps
  • kburke's avatar
    kburke
    Honored Guest
    Thanks. I guess I'm a little surprised that the best way to draw text onto the screen is with a third party library, given the ubiquitousness of text in games.
  • Unity 4.6 beta has a completely revamped UI system that allows you to place UI elements in the real world. Just attach a UI Canvas as a child to either the left or right camera, set it to world space, then add what other elements you want such as text images etc.