Forum Discussion

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

Gui don´t work

Hi,

please i Need help. I have buy a gui code, but it don´t work with Oculus Cams and unity. Can you help me. :P


using UnityEngine;
using System.Collections;

//ATTACH TO MAIN CAMERA, shows your health and coins
public class GUIManager : MonoBehaviour
// public static var main: Camera;
{
public GUISkin guiSkin; //assign the skin for GUI display
[HideInInspector]
public int coinsCollected;

private int coinsInLevel;
private Health health;

//setup, get how many coins are in this level
void Start()
{
coinsInLevel = GameObject.FindGameObjectsWithTag("Coin").Length;
health = GameObject.FindGameObjectWithTag("Player").GetComponent<Health>();
}

//show current health and how many coins you've collected
void OnGUI()
{
GUI.skin = guiSkin;
GUILayout.Space(5f);

if(health)
GUILayout.Label ("Health: " + health.currentHealth);
if(coinsInLevel > 0)
GUILayout.Label ("Cubes: " + coinsCollected + " / " + coinsInLevel);
}
}

3 Replies

Replies have been turned off for this discussion
  • "Black2011" wrote:
    Hi,

    please i Need help. I have buy a gui code, but it don´t work with Oculus Cams and unity. Can you help me. :P


    using UnityEngine;
    using System.Collections;

    //ATTACH TO MAIN CAMERA, shows your health and coins
    public class GUIManager : MonoBehaviour
    // public static var main: Camera;
    {
    public GUISkin guiSkin; //assign the skin for GUI display
    [HideInInspector]
    public int coinsCollected;

    private int coinsInLevel;
    private Health health;

    //setup, get how many coins are in this level
    void Start()
    {
    coinsInLevel = GameObject.FindGameObjectsWithTag("Coin").Length;
    health = GameObject.FindGameObjectWithTag("Player").GetComponent<Health>();
    }

    //show current health and how many coins you've collected
    void OnGUI()
    {
    GUI.skin = guiSkin;
    GUILayout.Space(5f);

    if(health)
    GUILayout.Label ("Health: " + health.currentHealth);
    if(coinsInLevel > 0)
    GUILayout.Label ("Cubes: " + coinsCollected + " / " + coinsInLevel);
    }
    }



    Have you tried setting the Canvas to render in world space? Have you seen this forum post as well? It's really good:
    https://forums.oculus.com/viewtopic.php?f=37&t=16710

    Also, this tutorial is really good about the new GUI system:
    https://www.youtube.com/watch?v=4d_l9Om ... 6c&index=1

    Apart from that, not sure what you bought, did you buy a package on the Asset store? The new Unity GUI is pretty good.
  • Hi, thanks

    Canvas is very cool, but i don´t know how can i import this gui in canvas or converted to canvas :oops:
  • Did you attach this to each Oculus camera? The main OVR camera has 3 parts, the left and right eye cameras and the center anchor point.

    I'm not sure what GUI.skin is, so not sure what else to suggest. The forum post I mentioned in the above post has an example project to download that I found really helpful for integrating the new UI. If you want a HUD, I would think that world space can still work with your code here, you just put the Canvas you want displayed under the middle anchor point and it should move with the head tracking I think.

    Hope some of that helped. Cheers.