Advertisement
dnnkeeper

Unity FPS Limit

Nov 27th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1.     public float goalFPS = 30;
  2.     private float millisecondsToWait;
  3.    
  4.     // Update is called once per frame
  5.     void Update () {
  6.    
  7.         float overflow = 1.0f/goalFPS - Time.deltaTime;
  8.        
  9.         if (overflow > 0.0f)
  10.             millisecondsToWait ++;
  11.         else
  12.             millisecondsToWait --;
  13.        
  14.         Thread.Sleep((int)Mathf.Clamp(millisecondsToWait, 0.0f, 1.0f/goalFPS * 1000.0f)); // clamp for sanity      
  15.        
  16.         if (SystemInfo.graphicsDeviceID == 0)
  17.             return;
  18.  
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement