Question by
kristiananton · May 11, 2016 at 02:10 PM ·
pause menu
(CS1525) and (CS8025) please help me!
using UnityEngine; using System.Collections;
public class PauseGame : MonoBehaviour { public Transform Canvas;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Canvas.gameObject.activeInHierarchy = false)
{
Canvas.gameObject.SetActive(true);
} else
{
Canvas.gameObject.SetActive(false)
}
}
}
}
Comment
Answer by Ali-hatem · May 11, 2016 at 02:42 PM
if (something == false) not if (something = false)& you might need to rename Canvas & decalre it as GameObject not Transform :
public GameObject obj;
void Update () {
if (Input.GetKeyDown(KeyCode.Escape)){
if(!obj.activeInHierarchy){//shorthand for "if(obj.activeInHierarchy == false)"
obj.gameObject.SetActive(true);
else{
obj.gameObject.SetActive(false);
}
}
}
}
Your answer
Follow this Question
Related Questions
save load not working so well 0 Answers
My cursor is gone when I go from my fps scene to the main menu. 0 Answers
How to stop the game but not the menu animations? 0 Answers
Pause Menu not showing 1 Answer