Pause Game When Function Is Enabled?

Okay I’m having a really big problem with this. I’ve been trying to pause the game when either a function is enabled, a collision with a certain gameobject happens, or when whenever. By the way I don’t mean pause the game when all of these things happen, I mean I tried them all but it doesn’t work for me. I just want to pause the game when I collect a power up, and wait for 3 seconds then un-pause the game. Time.timeScale never ever works for me by the way.

Look at this function:

public void SpeedUp()
	{
		Debug.Log( "SpeedUp()" );
		Time.timeScale = 0;
}

This is the beginning of the function as you can probably tell. I tried doing this and similar things but it won’t pause anything.
I also tried stopping time by collision, but I was told this wasn’t going to work because the gameObject I’m colliding with destroys itself therefore destroying the Time.timeScale = 0;, which means it never happens. Here it is anyways if anyone knows how to fix this:

public class PowerupScript : MonoBehaviour {

	
	void OnTriggerEnter2D(Collider2D other)
	{
		if (other.tag == "Player") {
			ControllerScript playerScript = other.gameObject.GetComponent<ControllerScript> (); 
			if (playerScript) {
				
				Time.timeScale = 0;
				
				// We speed up the player and then tell to stop after a few seconds
				playerScript.SpeedUp();
				
			}

				Destroy (gameObject);
		}
	}
	
	
}

I’m asking/begging you guys/gals. Please help.

Is the game slowing down? Is your debug call showing up in the console window?

If you want to “wait three seconds”, bear in mind that most of Unity’s time tracking – including Time.deltaTime and Time.time – is affected by timeScale. If you set timeScale to zero, all of those values will effectively stop ticking any time.

So, what can you do? You can use Time.realtimeSinceStartup, wait until that’s gone up by three seconds, and then reset the time scale.

float speedUpTime;

void SlowDown() {
    speedUpTime = Time.realtimeSinceStartup + 3f; //3 seconds from now
    Time.timeScale = 0f;
}

void SpeedUp() {
    speedUpTime = 0f; //set back to zero; effectively ignored after that
    Time.timeScale = 1f;
}

void Update() {
    //are we supposed to speed back up?
    if (Time.realtimeSinceStartup > speedUpTime) {
        SpeedUp();
    }
}

If you have done Time.timeScale = 0 , you will get time.deltaTime = 0, Here is my suggestion though it is not perfect. as in FixedUpdate it is render after each 0.02 sec I guess so you can add direct value to a float temp like temp+=0.02f and then you can check it if it is near your 2 sec and in that case you can do Time.timeScale =1;

Well I tried everything, nothing seemed to work out correctly for me. However, I managed to create a similar effect to stopping time, so I’ve solved my own problem. Thank you all though for even bothering to try and help me. I really appreciate it.