Net Core教程

unity中显示帧数c#代码

本文主要是介绍unity中显示帧数c#代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

using UnityEngine;

using System.Collections;

public class FPSDisplay : MonoBehaviour
{

float deltaTime = 0.0f;

void Update()
{

deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;

}

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;

//new Color (0.0f, 0.0f, 0.5f, 1.0f);

style.normal.textColor = Color.white;

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);

}

}

这篇关于unity中显示帧数c#代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!