Help: Strange OnGUI Not Working

This simple FPS meter works fine inside Unity, but once I put it on the Ouya, nothing appears!

using UnityEngine;

using System.Collections;

 

public class HudFps : MonoBehaviour 

{

public  float updateInterval = 0.5F;

 

private float accum   = 0; // FPS accumulated over the interval

private int   frames  = 0; // Frames drawn over the interval

private float timeLeft; // Left time for current interval

private float fps = 0f;

private string fpsString = "----";

void Start()

{

    timeLeft = updateInterval;  

}

 

void Update()

{

    timeLeft -= Time.deltaTime;

    accum += Time.timeScale/Time.deltaTime;

    ++frames;

 

    if( timeLeft <= 0.0 )

    {

        // display two fractional digits (f2 format)

this.fps = accum/frames;

this.fpsString = System.String.Format("{0:F2} FPS",fps);

// reset

timeLeft = updateInterval;

accum = 0f;

frames = 0;

}

}

void OnGUI()

{

if (fps < 20f)

GUI.color = Color.red;

else if (fps < 30f)

GUI.color = Color.yellow;

GUI.Label(new Rect(5, 0, 800, 600), fpsString);

}

}

Comments

  • standardcomb0standardcomb0 Posts: 6Member
    edited July 2013
    By the way the only enabled elements in the scene are a main camera and a gameobject with this component attached to it. Looks perfectly as expected in Unity. On Ouya, the FPS is nowhere to be found.

    Any help is greatly appreciated.
    Post edited by standardcomb0 on
  • standardcomb0standardcomb0 Posts: 6Member
    The issue seems to be positioning in the upper-left corner. My label was simply outside the screen for some reason.

    I would really appreciate some help understanding this difference in coordinate from my computer to my TV. Why is the origin outside of my television's view? How do I configure this so the visible upper left of the screen is (0,0)?
  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    That's the overscan issue. Bring the GUI in 5% from the sides.
    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
  • standardcomb0standardcomb0 Posts: 6Member
    Thanks!
  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    Here's a video to toggle the overlay.


    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
  • JLAlexander86JLAlexander86 Your MindPosts: 58Member
    Ok what am I missing?

    using UnityEngine;
    using System.Collections;

    public class PickupPrompt : MonoBehaviour
    {

        public Transform player;
        public float distancePrompt = 5;
        public Texture2D button;
        public string message;
       
        float screenW = Screen.width;
        float screenH = Screen.height;

        // Use this for initialization
        void Start ()
        {

        }
       
        // Update is called once per frame
        void Update ()
        {

        }
       
        void OnGUI()
        {
            if(player)
            {
                float distToPlayer = Vector3.Distance(transform.position, player.transform.position);
                if(distToPlayer <= distancePrompt)
                {
                    if(button) GUI.Label(new Rect((screenW/2)-(button.width/2), (screenH-72)-(button.height+(button.height/2)), (screenW/2)+(button.width/2), (screenH-72)-(button.height/2)), button);   
                   
                   
                }
            }
        }
    }

    If I backup 10% of 720, which i set the res to elsewhere, and then backup the height of the image shouldn't I be well within the safe area?
    The prompt appears in the editor but not on the Ouya.
  • JLAlexander86JLAlexander86 Your MindPosts: 58Member
    Now I'm completely stumped... I tried centering it with

    if(button) GUI.Label(new Rect(screenW/2,screenH/2,screenW/2+button.width,screenH/2+button.height), button);

    and in Unity it's pretty much center but on the Ouya it's in the bottom right corner of the screen?
  • JLAlexander86JLAlexander86 Your MindPosts: 58Member
    I figured it out by doing this

        void OnGUI()
        {
            if(player)
            {
                float distToPlayer = Vector3.Distance(transform.position, player.transform.position);
                if(distToPlayer <= distancePrompt)
                {
                    //if(button) GUI.Label(new Rect((screenW/2)-(button.width/2), (screenH-72)-(button.height+(button.height/2)), (screenW/2)+(button.width/2), (screenH-72)-(button.height/2)), button);   
                    //if(button) GUI.Label(new Rect(screenW/2,screenH/2,screenW/2+button.width,screenH/2+button.height), button);   
                    GUI.Label(new Rect(screenW/2,screenH/2,screenW/2+button.width,screenH/2+button.height),"screen.w "+ Screen.width + "screen.h " + Screen.height + "screenW "+ screenW + "screenH " + screenH);
                    /*Debug.Log(Screen.width);
                    Debug.Log(Screen.height);
                    Debug.Log(screenW);
                    Debug.Log(screenH);*/
                   
                }
            }
        }

    What I got was Screen.width and Screen.height were 1280x720 but my screenW and screenH were 1920x1080 so I was grabbing the width and height before my global controller called for the res change.
Sign In or Register to comment.