Advertisement
artemisart

Unity3d DeltaTime

Mar 27th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class DeltaTime : MonoBehaviour
  4. {
  5.     private float deltaTime = 0;
  6.     private float lastFrameTime = 0;
  7.     private static DeltaTime instance;
  8.    
  9.     void Awake ()
  10.     {
  11.         instance = this;
  12.     }
  13.    
  14.     void Update ()
  15.     {
  16.         deltaTime = Time.realtimeSinceStartup - lastFrameTime;
  17.         lastFrameTime = Time.realtimeSinceStartup;
  18.     }
  19.    
  20.     public static float get ()
  21.     {
  22.         return Time.timeScale == 1 ? Time.deltaTime : instance.deltaTime;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement