Snippets

David Fraj Unity - Mostrar FPS en la pantalla

Created by David Fraj last modified
using UnityEngine;
using System.Collections;
 
//HAY QUE APLICAR EL SCRIPT EN LA CAMARA 
 
public class FPSDisplay : MonoBehaviour
{
	float deltaTime = 0.0f;
 
 	//Al actualizar cada Frame
	void Update()
	{
		deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
	}
 
 	//Al mostrar el GUI
	void OnGUI()
	{
		int w = Screen.width, h = Screen.height;
 
		GUIStyle style = new GUIStyle();
 
		Rect rect = new Rect(0, 0, w, h * 2 / 100);
		style.alignment = TextAnchor.UpperLeft;
		style.fontSize = h * 2 / 100;
		style.normal.textColor = new Color (0.0f, 0.0f, 0.5f, 1.0f);
		float msec = deltaTime * 1000.0f;
		float fps = 1.0f / deltaTime;
		string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
		GUI.Label(rect, text, style);
	}
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.