Question by
tstratton01 · Dec 18, 2018 at 03:06 PM ·
user interface
UI Not Displaying
For some reason, when I press "X", the timescale functions work however none of the "Showpaused" or others work. Any ideas?
public Button resume;
public GameObject[] pauseMenu;
public GameObject[] optionsMenu;
public Button options;
public Button optionsBack;
void Start()
{
Time.timeScale = 1f;
pauseMenu = GameObject.FindGameObjectsWithTag("pause");
optionsMenu = GameObject.FindGameObjectsWithTag("options");
Hidepaused();
resume.onClick.AddListener(TaskOnClick);
hideOptions();
options.onClick.AddListener(showOptions);
optionsBack.onClick.AddListener(hideOptions);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.X))
{
Debug.Log("test");
if (Time.timeScale == 1f)
{
Time.timeScale = 0f;
Showpaused();
}
else
{
Time.timeScale = 1f;
Hidepaused();
}
}
}
void showOptions()
{
foreach (GameObject o in optionsMenu)
{
o.SetActive(true);
}
foreach (GameObject p in pauseMenu)
{
p.SetActive(false);
}
}
void Showpaused()
{
foreach (GameObject p in pauseMenu)
{
p.SetActive(true);
}
}
void hideOptions()
{
foreach (GameObject o in optionsMenu)
{
o.SetActive(false);
}
foreach (GameObject p in pauseMenu)
{
p.SetActive(true);
}
}
void Hidepaused()
{
foreach (GameObject p in pauseMenu)
{
p.SetActive(false);
}
}
void TaskOnClick()
{
Time.timeScale = 1f;
Hidepaused();
}
Comment
Answer by Vega4Life · Dec 18, 2018 at 03:35 PM
I am going to take a good guess and say that your pause menus and options menus are disabled in the scene when the game starts. Thus this doesn't work -
pauseMenu = GameObject.FindGameObjectsWithTag("pause");
optionsMenu = GameObject.FindGameObjectsWithTag("options");
FindGameObjects will not find gameObjects that are disabled.
What you could do is enable them, then put the above code in awake(). Then in start(), you call HideOptions(); HidePaused();
This allows you to find your gameObjects, but then immediately hide them.