How to Appease a pause menu in a game that changes it's time scale?

I am working on a games pause menu, it works fine, but my pause script conflicts with other scripts in the game. i have it so when the player hits a certain object, the time scale changes. the problem i am having is with my pause menu script, it goes something like this…

if (Input.GetKeyDown(KeyCode.Z)){
isPaused != isPaused;
}
if (isPaused == true){
Time.timeScale = 0;
}else{
Time.timeScale = 1;
}

how could i change it so the else statement reverts the time scale back to what it was before isPaused = true?

you create a private variable that will hold the previous value. Let’s say:

private float _previousTimeScale;

than, inside the if condition, you can do something like:

_previousTimeScale = (Time.timeScale != 0) ? (Time.timeScale) : (_previousTimeScale);

What this last line does is to simply verify if the current time scale is different than 0, if it is, it’ll save the time scale value, otherwise, it won’t.

then, you assign it to your time scale:

if (isPaused == true){ 
     Time.timeScale = 0; 
}else{ 
     Time.timeScale = _previousTimeScale; 
}

Makes sense?