It would be really nice if the Time class contained the real time it took to complete the last frame (i.e. not dependent on timeScale) and likewise that there was a WaitForRealSeconds(). This would make it a lot easier to run certain behaviors when the game is paused.
A current workaround would be to store and compare this at the beginning of each frame. This could be wrapped into the following utility. If not called every frame, it'll approximate the realtime per frame by dividing by the number of frames passed. (edit: fixed to actually work) Code (csharp): // File: MyTime // Usage: var realtime = MyTime.RealDeltaTime(); private static var lastFrameCalled = 0; private static var lastTimeSinceStartup = 0.0; private static var currentDeltaTime = 0.0; static function RealDeltaTime() { if (lastFrameCalled != Time.frameCount) { currentDeltaTime = (Time.realtimeSinceStartup - lastTimeSinceStartup) / (Time.frameCount - lastFrameCalled); lastFrameCalled = Time.frameCount; lastTimeSinceStartup = Time.realtimeSinceStartup; } return currentDeltaTime; } d.
This is a very useful method David! Any reason why it's buggy on Windows only? Seems that it doesn't get called; neither Windows Standalone nor Webplayer. Thanks for this, joe
What is not called? The function in this script is not called by itself, you need to call it to return the "realtime" delta time.
Sorry for leaving out the details... i'm using it properly as it works great on OSX. The same build made for windows, it is not working, as mentioned. It behaves as if it's not called at all. Haven't tried it with a dummy project so maybe it's something else in my code, but my use of it is pretty straightforward. Looking at it, I cannot tell why it would work on OSX, but the same code doesn't work on Windows.