Skip to content

Instantly share code, notes, and snippets.

@404ryannotfound
Created May 30, 2017 00:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 404ryannotfound/0aca8ae9b6fb2baa0e60e0036297cb6d to your computer and use it in GitHub Desktop.
Save 404ryannotfound/0aca8ae9b6fb2baa0e60e0036297cb6d to your computer and use it in GitHub Desktop.
Unity3d - Simple Frames Per Second script
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