ShowFps.cs
using System.Net.Mime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ShowFps : MonoBehaviour
{
private float _interval = 0.5f;
private int _frameCount = 0;
private float _timeCount = 0;
private float _frameRate = 0;
[SerializeField]
private Text _text;
private void Start()
{
Init();
}
private void Update()
{
MyUpdate();
}
private void OnDestroy()
{
MyDestroy();
}
private void Init()
{
}
private void MyUpdate()
{
_frameCount++;
_timeCount += Time.unscaledDeltaTime;
if (_timeCount >= _interval)
{
_frameRate = _frameCount / _timeCount;
_frameCount = 0;
_timeCount = 0;
}
_text.text = string.Format("FPS:{0:F1}",_frameRate);
}
private void MyDestroy()
{
}
}
网友评论