Unity FPS计算

FPS是指的游戏的刷新频率,一般是以1秒为单位计算的:

那么就非常容易算出FPS的帧率;

private const float update_Time=1f;

private float frames=0f;

private float time=0f;

private string fpsStr=string.empty;

void Update()

{

time+=Time.deltaTime;

if(time>=update_Time)

{

fps=(frames/time).ToString();

time=0f;frames=0f;

}

frames++;

}

void OnGUI()
{
GUI.Label (new Rect(Screen.width - 100, Screen.height - 45, 100, 20), fps);

}

是不是灰常简单呢

猜你喜欢

转载自blog.csdn.net/martins1994/article/details/81065255
今日推荐