Created
December 11, 2015 09:07
-
-
Save peroon/50dda0365e7a1aecaaca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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