-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFPSDisplay.cs
More file actions
34 lines (27 loc) · 927 Bytes
/
Copy pathFPSDisplay.cs
File metadata and controls
34 lines (27 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class FPSDisplay : MonoBehaviour
{
public float avgFramerate;
public float refresh = 0.5f;
string display = "{0} FPS";
private Text m_Text;
private IEnumerator Start()
{
m_Text = GetComponent<Text>();
var waitForSecondsRealtime = new WaitForSecondsRealtime(refresh);
while (true)
{
// Capture frame-per-second
int lastFrameCount = Time.frameCount;
float lastTime = Time.realtimeSinceStartup;
yield return waitForSecondsRealtime;
float timeSpan = Time.realtimeSinceStartup - lastTime;
int frameCount = Time.frameCount - lastFrameCount;
// Display it
avgFramerate = frameCount / timeSpan;
m_Text.text = string.Format(display, avgFramerate.ToString("0.00"));
}
}
}