Advertisement
KpoKec

FPS meter

Apr 12th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class FPSmeter : MonoBehaviour2 {
  7.  
  8.     public Text text;
  9.     public float updateTime = 0.5f;
  10.     private int frameCounter = 0;
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.         InvokeDelegate(UpdateMeter, updateTime);
  15.     }
  16.    
  17.     // Update is called once per frame
  18.     void Update () {
  19.         frameCounter++;
  20.     }
  21.  
  22.     void UpdateMeter()
  23.     {
  24.         string s = ((float)frameCounter / updateTime).ToString("F1");
  25.         frameCounter = 0;
  26.         text.text = s;
  27.         InvokeDelegate(UpdateMeter, updateTime);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement