What Updates are possible when Time Scale is 0 (or near 0)

Hi,

please could I get some help with this question:

what updates are possible when time scale is 0 or near 0? I have a pause screen with a button which I would like to change when pressed, however nothing happens when I try to make changes through an Update script.

I have seen that Updates() still process. But changes to text for example, using

object.guiText.Text="new text after button pressed"

doesn’t do anything.

Thanks for your help
Ryan

Hey Ryan,

Can’t tell you anything about why GUI events don’t get processed…if that is the problem.
But perhaps you can go about this a different way, say using a coroutine.

Is time already frozen when you press the button? If so why not unfreeze it for one frame, set the text and then freeze it again.
You can use a coroutine to wait for exactly 1 frame.

I doubt anyone will notice :slight_smile:

Hey Alex,

Thanks for e reply. Sounds like a great idea, to change the text and move on for just one frame.

This would be perfect, I actually did try to do something like this, briefly changed the timescale back to 1 after The button was pressed, the with an else statement changed it back to 0. But that didn’t work. I didn’t make use of co routines however.

Would you have anymore details on how the coroutine would look in code (or even just pseudo code) and also how to move forward only 1 frame?

Thanks for your help.

Regards
Ryan

Hey Dude,

Don’t have unity handy but you would do something like this:

C# version :slight_smile: …JS is simpler so check out the manual for syntax (don’t remember now)

  1. in the button click handling part fire off the coroutine:

// your other code

StartCoroutine(FreezeFrame(params if any));

// more of your code

  1. the actual coroutine:

private IEnumerator FreezeFrame(params if any) {

// scale time to 1
// set text

yield return new WaitForEndOfFrame();

//scale time to 0

}

Try it…theoretically this should work. :slight_smile:

Hey Alex,
That’s great, thanks. I will give it a try in JS as that what I normally code in. I will post my results.

Regards
Ryan

Hi Alex,
I have test the code and it worked, fantastic. Thank you very much for your help.

I create a new project to test the theory, and placed a GuiText object in the center of the screen to act as a button.
Here is the basic script I made to test the theory:

var vGobj_button_txt : GameObject;

function Awake(){

	//Set timescale here as if the game is paused right away
	Time.timeScale=0;		
	
}

function Update () {

	//Check for mouse click
    if (Input.GetMouseButton (0)){
        var         mx = Input.mousePosition.x;
        var         my = Input.mousePosition.y;
    
        print(" PAUSE.... mousex=" + mx + "  mousey=" + my);
        
        
        //Check for button press
        if ( mx>459  mx<568  my>370  my< 386 )
        {
            Button_Press_Reaction();
        }
    }
}

function Button_Press_Reaction(){
	
	//Set Timescale to 1 - normal, just for the update of the text
	Time.timeScale=1;
	
	//Change the button text
	vGobj_button_txt.guiText.text = "PRESSED!";
	
	//Wait for a single frame to be drawn
	yield WaitForEndOfFrame();
	
	//Set Timescale back to 0 - paused again
	Time.timeScale=0;
	
}

Cool. I actually helped someone!

:smile:

Good luck with the rest of your project mate.