Skip to content

Instantly share code, notes, and snippets.

@peroon
Created December 11, 2015 09:07
Show Gist options
  • Save peroon/50dda0365e7a1aecaaca to your computer and use it in GitHub Desktop.
Save peroon/50dda0365e7a1aecaaca to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class FPS : MonoBehaviour {
Text text;
int frameCount;
float prevTime;
void Start () {
Application.targetFrameRate = 60;
text = this.GetComponent<Text> ();
}
void Update () {
++frameCount;
float time = Time.realtimeSinceStartup - prevTime;
if (time >= 0.5f) {
var fpsFloor = Mathf.Floor(frameCount / time);
text.text = fpsFloor.ToString();
frameCount = 0;
prevTime = Time.realtimeSinceStartup;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment