- Home /
UI won't activate
I'm trying to get my console UI to open when you press enter or return. But it just wont work. I think my code is correct but I'm not sure.
My code:
public static bool Console = false;
public GameObject consoleUI;
void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
if (Console)
{
Open();
}
else
{
Close();
}
}
}
public void Open()
{
consoleUI.SetActive(true);
}
public void Close()
{
consoleUI.SetActive(false);
}
Answer by Neengash · Feb 05, 2021 at 06:52 PM
Is the Console
value, changed in any other script ?
If that's not the case, it is set to false
at it's declaration and never changed, so in every Update
in which the Return key is pressed it will just call the Close
method.
If you prettend to make it toogle on and off by pressing Return, you'd have to change the Console
value, and the conditional should go the other way around:
if (Input.GetKeyDown(KeyCode.Return))
{
if (!Console)
{
Open();
}
else
{
Close();
}
}
}
public void Open()
{
consoleUI.SetActive(true);
Console = true;
}
public void Close()
{
consoleUI.SetActive(false);
Console = false;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Navigate UI with gamepad 0 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Select Car - Multiple prefabs 1 Answer