Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

UI into OVR cameras

Discussion in 'AR/VR (XR) Discussion' started by Guardiandota, Dec 20, 2014.

  1. Guardiandota


    Nov 16, 2014
    Hi there, Im newbie to oculus and right now im testing my project and i got an issue:

    Before i got the oculus I was using standart main camera and somewhere here I found a script that pops up GUI when object is picked up (in my case its a paper)
    Now, i cant see gui through the oculus.
    I think that the script needs to be changed but unfortunately i dont know how

    Here is the script provided by CharlesD

    using UnityEngine;
    using System.Collections;

    public class PickupNote : MonoBehaviour {

    //Maximum Distance you Can Pick Up A Book
    public float maxDistance = 1.5F;

    //Your Custom GUI Skin with the Margins, Padding, Align, And Texture all up to you :)
    public GUISkin skin;

    //Are we currently reading a note?
    private bool readingNote = false;

    //The text of the note we last read
    private string noteText;

    public AudioClip pickupSound;

    void Start () {

    //Start the input check loop
    StartCoroutine ( CheckForInput () );


    private IEnumerator CheckForInput () {

    //Keep Updating
    while (true) {

    //If the 'E' was pressed and not reading a note check for a note, else stop reading
    if (Input.GetKeyDown (KeyCode.E)) {

    if (!readingNote)
    CheckForNote ();
    readingNote = false;


    //Wait One Frame Before Continuing Loop
    yield return null;



    private void CheckForNote () {

    //A ray from the center of the screen
    Ray ray = Camera.allCameras(new Vector3(0.5F, 0.5F, 0));
    RaycastHit data;

    //Did we hit something?
    if (Physics.Raycast (ray, out data, maxDistance)) {

    //Was the object we hit a note?
    if ( == "Note") {

    //Get text of note, destroy the note, and set reading to true
    AudioSource.PlayClipAtPoint(pickupSound, transform.position);
    noteText = data.transform.GetComponent <Note> ().Text;
    Destroy (data.transform.gameObject);
    readingNote = true;




    void OnGUI () {

    if (skin) = skin;

    //Are we reading a note? If so draw it.
    if (readingNote) {

    //Draw the note on screen, Set And Change the GUI Style To Make the Text Appear The Way you Like (Even on an image background like paper)
    GUI.Box (new Rect (650f, 50f, 1f, 1f), noteText);




    Im using Unity 4.5.5, so i dont have any Canvas-like stuff and etc. 4.6 just didnt run on my pc
    Any help is appreciated
  2. OpticalOverride


    Jan 13, 2013
    The problem is your script is drawing the text directly to the screen in the OnGUI function. This doesn't work in VR (it's like trying to draw text on directly your eyeball, it doesn't make sense). In order to view a GUI, or anything in VR for that matter, it has to be a 3D object in the scene, just like actual reality (eh? see what I did there?).

    Without 4.6, you're going to need to use something like a Text Mesh in order to have 3D text. Just set a new TextMesh as a child of the object you want it to follow. Then you'll likely need a script that uses Unity's LookAt function attached to the TextMesh, which tells the TextMesh to rotate the text to face the player.

    I don't have time to explain any further, if either of the two concepts I explained above are unfamiliar (TextMesh component or the LookAt function), you can look up tutorials online for both.

    Hope this helps!
  3. Guardiandota


    Nov 16, 2014
    Thanks ! Ive tried to create a mesh and add text prefab into the mesh, it works fine i can see it through the oculus, but the problem is that LookAt does not work. The default position of the prefab (lets say "paper") is not the thing i need so i rotated it. Now i need to set y rotation ( and most probably x positioning) values to the camera position so i can see it from any x position i come into the trigger area

    sorry for my english :(


    so i managed to get the paper look at me (through PlayMaker) now i need to set up the distance between paper and Player, because sometimes player can try to read the paper on the edge of the trigger or right on the middle of it. In second case the paper appears right on the face of the player which is bad. Need to fix it again though the playmaker if possible
    Last edited: Dec 21, 2014
  4. GoesTo11


    Jul 22, 2014
    Was there a reason that you aren't using 4.6?
  5. Arowx


    Nov 12, 2009
    What you can do is setup an empty child object notePos located in front of the player and as a child of the player. Then when they trigger a Note you move the note to this position and change the parent of the note to the notePos.

    This has the effect of moving any note in front of the player, if you set the parent of the note to the player it will stay in position in front of the player even if they move. If not it will just appear in front of them when they trigger it and when they move stay in that position.