- Home /
UI Escape menu script not working.
I'm (just beginning) in making a script for an escape menu for my game. The menu disappears when I start my game (like it's intented to) but I can't open it...
This is my script so far:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class EscapeMenu : MonoBehaviour {
public GameObject MainEscapeMenu;
bool MenuIsOpen;
void Start() {
MainEscapeMenu.GetComponent<RawImage>().enabled = false;
MenuIsOpen = false;
}
void AccessMenu() {
if(Input.GetKeyDown("p")){
if(MenuIsOpen == false){
MainEscapeMenu.GetComponent<RawImage>().enabled = true;
MenuIsOpen = true;
}
if(MenuIsOpen == true){
MainEscapeMenu.GetComponent<RawImage>().enabled = false;
MenuIsOpen = false;
}
}
}
}
Did you write the Access$$anonymous$$enu() into Update() function?
I tried to use Update() and it had no other effect. So I'm atleast trying to make my script sorted before is starts to look like a hoarders: script edition episode.
Answer by Trevdevs · May 13, 2017 at 02:04 AM
AccessMenu is never being called therefore is never checking for you pressing the p key whenever I have any Input detection I need I always do it in an update function.
void Update()
{
if(Input.GetKeyDown(KeyCode.P))
{
AccessMenu();
}
}
void AccessMenu() {
if(MenuIsOpen == false){
MainEscapeMenu.GetComponent<RawImage>().enabled = true;
MenuIsOpen = true;
}
if(MenuIsOpen == true){
MainEscapeMenu.GetComponent<RawImage>().enabled = false;
MenuIsOpen = false;
}
}
Answer by $$anonymous$$ · May 14, 2017 at 07:20 PM
I'm using SetActive
menu.SetActive(false);
syntax is from JS so look into documentation of SetActive for C code
Your answer
Follow this Question
Related Questions
Component name for raw image. 1 Answer
LeanTween.moveLocal sometimes snaps to position rather than moving over time 0 Answers
UI fade with CanvasGroup vs of Image.color.alpha or Text.color.alpha performance 1 Answer
LeanTween.moveLocal sometimes snaps to position rather than moving over time 0 Answers
Most efficient way to check if a component is null for a canvas or UI? 1 Answer