I’m trying to toggle time scaling using a GetKeyDown check. The trouble is that when I press the key, nothing happens. I have no errors in the console, and I’ve tested that the GetKeyDown and the if statements are working by adding a print event, which works fine. I’m also moving the object along its Y axis using transform.Translate, just to see whether timescaling is working.
Here’s the code:
function Update ()
{
transform.Translate (0, 0.02, 0);
if ( Input.GetKeyDown ( "s" ) )
{
if ( Time.timeScale == 1.0 )
{
Time.timeScale = 0.2; //slow time down
print ( "Time slowed." );
}
else
{
Time.timeScale = 1.0; //regular speed
print ( "Time Restored." );
}
}
Like I said, no errors, and the printing is working just fine. So what’s the problem here?