Forum Discussion

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

GUI from main into OVR Cameras

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 ();
else
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 (data.transform.name == "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)
GUI.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);

}

}

}


I use Unity 4.5.5, so i dont have any Canvas-like stuff and etc.
Any help is appreciated

2 Replies

Replies have been turned off for this discussion
  • Anything preventing you from upgrading to 4.6? Its very painless : )
  • I would also recommend using Unity's new uGUI, which is available in 4.6 and up. If you need to use the old Unity GUI, then try rendering it to a RenderTexture and then displaying that on a quad in the world. That's how OVRMainMenu is implemented for Unity 4.5.