Question by
iHadigamer · Feb 21, 2019 at 05:16 AM ·
scripting problembuttonscript.panel
I want to do a pause panel
I have a problem at selecting button Pleas help Thx
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PauseManu : MonoBehaviour
{
public static bool GameisPaused = false;
public Button escape;
public GameObject pauseMenuUI;
void Update()
{
if (Input.GetButtonDown(escape))
{
Comment
Here is what you must do :
public $$anonymous$$eyCode escape;
void Update()
{
if (Input.Get$$anonymous$$eyDown(escape))
{
//Do stuff
}
}
//And you need to assign the key you want in the editor ;) Hope I helped
Answer by TheSnage · Dec 29, 2019 at 05:27 AM
u could set the pause menu to active if escaped is pressed and have it set to inactive when a button on the pause menu is pressed and at the start like this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PauseManu : MonoBehaviour
{
public static bool GameisPaused = false;
public Button escape;
//added button variable for resume(this could be space or something)
public Button resume;
public GameObject pauseMenuUI;
//added start function that runs as soon as the script is to set the pause menu to inactive
void start()
{
//added action to start function to set the pause menu to inactive
pauseMenuUI.SetActive(false);
}
void Update()
{
if (Input.GetButtonDown(escape))
{
//added action to if statement to set the game object to active when escape is pressed
pauseMenuUI.SetActive(true);
}
//added if statement to check every frame for when the resume button is pressed
if (Input.GetButtonDown(resume))
{
//added action to set te pause menu back to inactive after resume button is pressed
pauseMenuUI.SetActive(false);
}
}
}
the SetActive trait, by the way, is like unchecking or checking the box next to a gameobject's name