How to "Freeze" game

Hello everyone,

I am trying to make a sort of adventure rpg game and am curently working on the inventory. There is only one thing that i can’t seem to figure out and i can’t seem to find any helpfull info on it.

Curently whenever I open the inventory bij pressing I it opens and I can click everything, BUT the game keeps playing in the background. So the camera follows the mouse and if i click doesn’t matter where the character attacks. I don’t want that to happen and whas hoping someone here can explain to me how i can change that with a script.

Thank you in advance :slight_smile:

Hi yaramatris95,
You can use Time.timeScale to set the speed of your game.

calling Time.timeScale = 0.0f; will pause the game and =1.0f will resume.

2 Likes

I would consider two options. One, you disable any scripts that you need to disable and enable them when not paused, but this can get messy depending on your project.

Other option is you set a static variable “isPaused” and any action that needs to can check this variable before running any code.

The use of timeScale can work, but be aware that timescale doesn’t effect everything. It may not work for you to stop what you need it to stop.

1 Like

Thank you both for your answers!

i used the timeScale to pause the game and i disabled the script for the camera movement and now my inventory is perfect :smile: I have learned a lot this way :slight_smile:

2 Likes