How can i make pause menu
i want to make a 2d game in android using C# can any one help me plz ?
Comment
Answer by ElementalVenom · Sep 27, 2015 at 05:50 PM
Hello Hajamat. A pause menu is rather simple. Some code off the top of my head would be this:
bool pause=false;
Void Start(){
}
Void Update(){
if(pause){
//Disable Movement Scripts Example:
GetComponent<PlayerMovement>().enable=false;
}else {
//Enable Movement Scripts
GetComponent<PlayerMovement>().enable=True;
}
}
void OnGUI(){
GUI.skin.label.fontSize=Screen.height/50;
if(GUI.Button(new Rect(Screen.width/20,Screen.height-Screen.height/10,Screen.width/20,Screen.height/20),"Pause")){
pause=true;
}
if(pause){
//Draw pause menu stuff.
}
}
Thats just off the top of my head so there might be errors, But it should work.
Answer by lloladin · Sep 30, 2015 at 08:55 PM
the simpliest way to pause the game is Time.timescale = 0; this will Pause the game but if you press any keys while doing this once you set the Time.timescale = 1; the code from the keys will execute so the way i usally do this is in my GameManager Script thats easyli accesible from all scripts i make a bool called Pause and check on all Scripts that has Key press commands
Example
if (FindObjectOfType<GameManager>().Pause != true && getKey(keycode.Space))
{
// execute code
}
else
{
// do nothing the game is pasued
}