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 38 39 40 41 42 43
| using UnityEngine; using System.Collections; using System.Collections.Generic;
public class ShowFPS : MonoBehaviour { public int fpsTarget;
public float updateInterval = 0.5f; private float lastInterval; private int frames = 0; private float fps;
void Start() { Application.targetFrameRate = 60;
lastInterval = Time.realtimeSinceStartup; frames = 0; }
void Update() { ++frames; float timeNow = Time.realtimeSinceStartup; if (timeNow >= lastInterval + updateInterval) { fps = frames / (timeNow - lastInterval); frames = 0; lastInterval = timeNow; } }
void OnGUI() { GUI.Label(new Rect(200, 40, 100, 30), fps.ToString()); } }
|