using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class FpsCounter : MonoBehaviour
{

	// FPS counter data
	private int frameCount = 0;
	private float worstDelta = 0f;
	private float dt = 0f;
	private float fps = 0f;
	private float minFps = 0f;
	private TextMeshProUGUI textComponent;

	// Use this for initialization
	void Start ()
	{
		this.textComponent = this.GetComponent<TextMeshProUGUI> ();


	}
	
	// Update is called once per frame
	void Update ()
	{
		frameCount++;
		
		dt += Time.deltaTime;
		if (Time.deltaTime > worstDelta) {
			worstDelta = Time.deltaTime;
		}
		
		if (dt > 1.0f) {
			fps = frameCount / dt;
			minFps = 1f / worstDelta;
			worstDelta = 0f;
			frameCount = 0;
			dt -= 1.0f;
			
			this.textComponent.text = string.Format ("{0:0.0} - {1:0.0}", fps, minFps);
		}
	}
}
