Created
May 30, 2017 00:28
-
-
Save 404ryannotfound/0aca8ae9b6fb2baa0e60e0036297cb6d to your computer and use it in GitHub Desktop.
Unity3d - Simple Frames Per Second script
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; | |
namespace FBCapture | |
{ | |
public class FPSScript : MonoBehaviour | |
{ | |
/// <summary> | |
/// Delta time | |
/// </summary> | |
float deltaTime = 0.0f; | |
/// <summary> | |
/// It will be used for printing out fps text on screen | |
/// </summary> | |
Text text; | |
void Start() | |
{ | |
text = GetComponent<Text>(); | |
} | |
void Update() | |
{ | |
deltaTime += (Time.deltaTime - deltaTime) * 0.1f; | |
float msec = deltaTime * 1000.0f; | |
float fps = 1.0f / deltaTime; | |
text.text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment