Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Unscaled time invoke?

Discussion in 'Scripting' started by Marscaleb, Feb 20, 2015.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    300
    Is there any simple method to invoke a function but have it count on unscaled time?
    I have some functions that I need to invoke while the time scale is set to 0 (paused) but the normal invoke method uses scaled time, so when the game is paused like that it never gets invoked.

    I can arrange some functions in my update that can manually count the unscaled deltatime, but that seems like such a waste of time and extra code. Plus that extra code is going to start getting really complicated if I ever find I need to invoke more functions that use unscaled time.
     
  2. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    189
    Its your lucky day! :D I have written classes to accomplish this very task. Call it like this, note that timeScale is set to 0, yet 5 seconds later, MyFunc runs.
    Code (CSharp):
    1.     void Start () {
    2.         Invoker.InvokeDelayed(MyFunc, 5);
    3.         Time.timeScale = 0;
    4.     }
    5.  
    6.     void MyFunc()
    7.     {
    8.         Debug.Log ("adfg");
    9.     }
     

    Attached Files:

    OneDragutin likes this.
  3. justinpando

    justinpando

    Joined:
    Nov 17, 2014
    Posts:
    4
    Hey, I really like this script! I'd really like to use it in my game, just wanted to check the license - would you be willing to add something similar to the MIT license to your script so it's clear what permissions you're giving for use?

    Here's the example:
    http://opensource.org/licenses/MIT
     
  4. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    189
    Glad you like the script! I have re-uploaded it in my original post with the MIT license for you.