topical media & game development

talk show tell print

lib-unity-book-11-FPSdisplay.js / js



  /* Script Provided by Will Goldstone as part of Unity Game Development Essentials book assets */
  /* Please Do Not Remove this comment - this script is for reference only */
  private var nextUpdate : float = 0;
  private var frames : float = 0;
  private var fps : float = 0;
  private var updatePeriod = 0.5;
  
  function Update() {
  
          frames++;
          
          if (Time.time > nextUpdate){
                  
                    fps = Mathf.Round(frames / updatePeriod);
                                  guiText.text = "Frames Per Second: " + fps;
                  nextUpdate = Time.time + updatePeriod;
                  frames = 0;                
          }
          
  }
  
  @script RequireComponent(GUIText)


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.