It looks like you're new here. If you want to get involved, click one of these buttons!
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
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].
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].
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.
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?
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.