How to toggle between paused mode and running mode?

Hello guys, I’m trying to code a script to toggle between the game while paused and the game while running by pressing the P key.
I already coded a function to do that, but the game is never paused, keeps running like if nothing happened.

bool trocar = false;
	
	// Update is called once per frame
	void Update () {
		Trocar();
	}
	
	void Trocar () {
		if (Input.GetKeyDown(KeyCode.P)) {
			if(trocar == false) {
				Time.timeScale = 0;
				Time.fixedDeltaTime = 0.02f * Time.deltaTime;
				trocar = true;
			}
			if(trocar == true) {
				Time.timeScale = 1;
				Time.fixedDeltaTime = 0.02f * Time.deltaTime;
				trocar = false;
			}
		}
	}

In this function, when I press the P key, it tests if the variable trocar is true or false. If it’s false, then it pauses the game, if it’s true, it puts the game running again. The problem is that if(trocar == true) always run after if(trocar == false), never pausing the game.
What changes I need to do to fix this?

Replace:

if(trocar == true)

With:

else

EDIT:

Actually you can shorten it even more by doing it like:

if(!trocar)
{
    //...
}
else
{
    //...
}