Scene pause Unity 5 (c#)

Pausing a scene

using UnityEngine;
using System.Collections;
//Finalmarco.com

public class PausaGioco : MonoBehaviour {
	
	bool paused = false;
	
	
	void Update () 
	{
		if(Input.GetKeyDown("p")) 
		{
			gamePaused();
		}

	}
	
	void OnGUI()
	{
		if (paused == true) 
		{
			GUILayout.Label("GAME IS PAUSED");
			if(GUILayout.Button ("CLICK TO UNPAUSE"))
			{
				gamePaused();
			}
		}
	}
	
	void gamePaused()
	{
		if (Time.timeScale == 1) 
		{
			Time.timeScale = 0;
			paused = true;
		}
		
		else
		{
			Time.timeScale = 1;
			paused = false;
		}
	}
}

 

Questions? Suggestions? Please leave a comment below.
I've really saved your ass? Buy me a beer

Tagged with: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*