Justin Hur
Game Programmer
Documentation
Objective:
Create a Pause Function that will be activated when the Escape Key is pressed. The Pause Function should stop all functionality of the player, the enemy, the projectiles, etc.
​
Process:
I searched online to see the more typical solutions to freezing everything and found that setting Time.timeScale = 0 should make things freeze since nothing is going on runtime. However, a problem is that a lot of our systems don't use timeScale. So our enemies would still run like normal, and the playable character would still be fully functional. I tried researching other solutions, but nothing came to avail. I even attempted using our code for time stop, but I dont believed it worked.
​
So the next course of action was to created an instance to the class and make a public bool called isPaused, which is to determine whether pause is active or not. Then setting all scripts to have a condition of if isPaused is true, then return. Doing this makes it so that the rest of the code in the update function won't activate.
​
For the player scripts, I made it so that the player's velocity would be set to vector3.zero so that the character doesnt slide across the room. GunControl didnt need additional code.
​
For the projectiles, I did the similar solution that I did with the player's movement script. I set the rigidbody's velocity to zero. Luckily, when the game is unpaused, the projectiles still on screen will run like normal.
​
For the enemy scripts, I had to go the parent script and set so that the code agent.isStopped set to true, then set it to false when the game is unpaused. For the charger enemy, because the Charger would slide before coming to a complete stop, so I set agent.autoBreaking to true when the game is paused, then revert when it's not paused. For the sounds of the charger, I had to stop it otherwise the sound would keep looping.
The sentinel enemy I had to place the if statement in the firing cool down method, because if not, then the sentinel could shoot out multiple sets of projectiles when the game is unpaused due to a time.deltatime still running.
​
​The TimeManager scrip was the most tricky to deal with. I had to set multiple conditions in order to get things working semi properly. If I left the original if statement as is, then the timestop would turn off while the game was paused, which didn't seem right. So then I made an additional if statement where it was if the game was paused, the escape key is still pressed, and the leftshift key is still pressed; then the game would still be in timestop when unpaused. However, this made it so that the game is still in timestop when unpaused even though the leftshift key isn't pressed. I'm not sure what is causing this.