Skip to main content
Up and Coming
March 13, 2015

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);
}
}
    This topic has been closed for replies.

    3 replies

    Inspiring
    March 13, 2015
    "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.
    Check out my Mobile VR Jam 2015 title Man Overboard! - Try the DK2 Version if you don't have a Gear VR
    Black2011Author
    Up and Coming
    March 13, 2015
    Hi, thanks

    Canvas is very cool, but i don´t know how can i import this gui in canvas or converted to canvas :oops:
    Inspiring
    March 13, 2015
    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.
    Check out my Mobile VR Jam 2015 title Man Overboard! - Try the DK2 Version if you don't have a Gear VR