How can I pause my game

i need to pause my game. i’ve tried things like setting global time to 0, but some things still happened. i need something like the pause in the unity editor that’s in between play and next frame at the top of the unity editor screen

I was having the same problem but came up with the solution. You need to create a bool, from there use the Time.timeScale function. Example code :

public class Pause : MonoBehaviour {

        bool paused = false;
	
	// Update is called once per frame
	void Update () {
		
		if(Input.GetKeyDown(KeyCode.P)){
			paused = togglePause();
		}
		
	}
	
	void OnGUI()
	{
		if(paused)
		{
			GUILayout.Label("Game is paused!");
			
		}
	}
	
	bool togglePause()
	{
		if(Time.timeScale == 0f)
		{
			Time.timeScale = 1f;
			return(false);
		}
		else
		{
			Time.timeScale = 0f;
			return(true);   
		}
	}

}

Hope this helps!

One way would be to use a boolean. If your boolean is true you could allow things to play and if it is false do not. You do not usually need to pause your entire game. just the timers and movement scripts, basically anything that would be noticeable to the player. For 3d physics. it would be more complicated so i wouldn’t touch that without knowing what your doing. But you could just set timescale like you have been alongside the boolean.