Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unscaled time invoke?

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

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    327
    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:
    241
    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:

    rathpanyowat and OneDragutin like 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:
    241
    Glad you like the script! I have re-uploaded it in my original post with the MIT license for you.