atr_ljf
2018-08-15 b2e9d05f8830e51b1c3e1829ebb12064cde3ab6e
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
35
36
37
var updateInterval = 0.5;
var x_location = 5;
var y_location = 5;
 
private var lastInterval : double; // Last interval end time
private var frames = 0; // Frames over current interval
private var fps : float; // Current FPS
 
 
function Awake () {
    useGUILayout = false;
}
 
 
function OnGUI () {
    GUI.Label (Rect(Screen.width-x_location, Screen.height- y_location, 100, 30), "FPS: " + fps.ToString("f2"));
}
 
 
function Start()
{
    lastInterval = Time.realtimeSinceStartup;
    frames = 0;
}
 
 
function Update()
{
    ++frames;
    var timeNow = Time.realtimeSinceStartup;
    if( timeNow > lastInterval + updateInterval )
    {
        fps = frames / (timeNow - lastInterval);
        frames = 0;
        lastInterval = timeNow;
    }
}