I have an issue with the code for Submenu. Someone to help me ?
Hello,
I would like to have two main menu : one on the left side (activated by the button LB) and one on the right side (activated by the button RB)
My idea is : when i have my "left main menu" (by keeping pressed LB) i can enter in the sub menu by pushing RB and when i have my Right main menu activated (by keeping pressed RB), i can enter in the sub right menu by pressing LB
The problem is ... my code don't understand at all, and if i press LB after RB or RB afterLB... it is the same ... I always enter in my right sub menu.
Could you help me ? This is my test code
if (Input.GetButton("LB"))
{
valueText.text = "LB";
if (Input.GetButton("RB"))
{
valueText.text = "RB after LB";
}
}
if (Input.GetButton("RB"))
{
valueText.text = "RB";
if (Input.GetButton("LB"))
{
valueText.text = "LB after RB";
}
}
Answer by tormentoarmagedoom · Jul 30, 2018 at 09:06 AM
Good day.
As you are using same buttons you need to "tell the code" where you come from. So best solution is to have 2 bool variables to detect that.
bool RightActive;
bool LeftActive;
if (Input.GetButton("LB") && RightActive==false)
{
valueText.text = "LB";
LeftActive = true;
if (Input.GetButton("RB"))
{
valueText.text = "RB after LB";
}
}
else
{
LeftActive=false;
}
if (Input.GetButton("RB") && LeftActive==false)
{
valueText.text = "RB";
RightActive=true;
if (Input.GetButton("LB"))
{
valueText.text = "LB after RB";
}
}
else
{
RightActive=false;
}
Something like this. (Maybe i forget some condition but this is the idea. To prevent code to execute wrong if)
OR you can do 4 diferent if in the same level (not one inside other) the first detect the first clik and activate a bool, the second activate the submenu if the clik and the bool are true. The same for the other side.
Bye!!
Thank you very much, I will test that immediatly :) Have a nice day