Time for action – adding code to pause the game Scene
In BeginState
, we're going to set timeScale
to zero to pause the Scene. Then before switching to PlayState
, we'll set it back to normal speed. Perform the following steps:
- Modify
BeginState
in two places as shown in the next screenshot. - Save the file.
What just happened?
An analysis of the code shown in the preceding screenshot is as follows: On the BeginState
class
Line 14: Time.timeScale = 0;
- This line makes time in the game to stop
Line 29: Time.timeScale = 1;
- This sets the game speed back to normal when switching to
PlayState
Click on Play again. Now the Cube GameObject is suspended in air. Click ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.