当前位置:   article > 正文

Unity3D 显示FPS_unity3d fps游戏

unity3d fps游戏

每秒传输帧数(Frames Per Second)

  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. public class FpsUI : UIBase
  4. {
  5. private Text FpsText;
  6. private float time;
  7. private int frameCount;
  8. private void Awake()
  9. {
  10. InitUI();
  11. }
  12. public override void InitUI()
  13. {
  14. FpsText = GetComp<Text>("FpsText");
  15. }
  16. void Update()
  17. {
  18. time += Time.unscaledDeltaTime;
  19. frameCount++;
  20. if (time >= 1 && frameCount >= 1)
  21. {
  22. float fps = frameCount / time;
  23. time = 0;
  24. frameCount = 0;
  25. FpsText.text = fps.ToString("f2");//#0.00
  26. FpsText.color = fps >= 20 ? Color.white : (fps > 15 ? Color.yellow : Color.red);
  27. }
  28. }
  29. }

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号