Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

TimeScale issue

Discussion in 'Scripting' started by 2dgamemania, Nov 13, 2016.

  1. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    Hi,

    I am using UnityScript and I use Time.timeScale=0 to pause my game.

    When I pause the game, I then have a user interface up which uses the WaitForSeconds function. The problem is when I have Time.timeScale set to 0 (paused) the WaitForSeconds function doesnt work with my UI. I found a work around but it seems to be in c#.

    I then found out that there is a WaitForSecondsRealtime function but I get a unknown identifer when running this. I'm guessing cause i'm using a older version number? I'm using 5.3.1f1.

    Can anyone suggest the best way forward

    Thanks

    Dave
     
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Link?
    Very unlikely, Its been around for as long as I can remember.
    Also could you post your code for the WaitForSecondsRealtime. It seems that it is used exactly the same as WaitForSeconds.
    https://docs.unity3d.com/ScriptReference/WaitForSecondsRealtime.html
     
  3. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    I created a new project to keep it simple and got the same error "unknown identifier"

    Heres the code
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. function Start () {
    5.  
    6. }
    7.  
    8. function Update () {
    9.     testfunction();
    10. }
    11.  
    12. function testfunction() {
    13.         yield WaitForSecondsRealtime (5);
    14. }
    15.  

    I have a animate function which prints out a character at a time and this is why I want to use the wait function. function below. I could just use yield by itself as that uses the next frame rather than time. It works but I'm guessing it would alter the speed of the text depending on how fast the computer is?

    Code (csharp):
    1.  
    2. function AnimateText(strComplete : String)
    3.     {
    4.         Time.timeScale = 0;
    5.         var i: int = 0;
    6.         str = "";
    7.         while( i < strComplete.Length ){
    8.             str += strComplete[i++];
    9.  
    10.         //THIS IS WHERE MY PROBLEM IS
    11.  
    12.             //yield //could i use this but its based on the next frame, not time
    13.             //yield WaitForSeconds(0.02); //doesnt work when you use timescale set to 0
    14.             //yield WaitForSecondsRealtime (5);  //comes up with unknown identifer
    15.  
    16.             GetComponent.<AudioSource>().Play();
    17.             textbox.text=str;
    18.         }
    19.     }
    20.  
    21.  
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    yield return new WaitForSecondsRealtime(5) not yield WaitForSecondsRealtime(5)
     
  5. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    i'm using unityscript so dont think that will work unfortunately?
     
  6. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    in the end I upgraded to the latest version of unity (and had to amend some stuff which the upgrade changed) and the yield WaitForSecondsRealtime(5) function worked.

    thanks for the help