- Home /
Question by
Sobe459 · Jun 04, 2013 at 04:37 PM ·
buttondisappearrepeatrepeatbutton
Repeat Button disappearing?
Im having an issue when i click the left button my right button will disappear until i unclick the left. But when i hit the right button my left button stays. Please help. Thank you.
if (GUI.RepeatButton(new Rect(10,550,50,30),"Left")) {
hAxis = -1;
}
else if (GUI.RepeatButton(new Rect(60,550,50,30),"Right")){
hAxis = 1;
}
else {
hAxis = 0;
}
Comment
Best Answer
Answer by karl_ · Jun 04, 2013 at 04:44 PM
The 'else' after the Left button is what causes the Right button to disappear. That conditional basically is this:
Show 'Left' button
If 'Left' button is not pressed, show 'Right' button
If 'Right' button is not pressed, hAxis is 0
Any time a condition is met, subsequent 'else' statements are not evaluated.
So an easy fix would be something like this
void OnGUI()
{
// Set hAxis to zero to start with
int hAxis = 0;
if (GUI.RepeatButton(new Rect(10,550,50,30),"Left"))
{
hAxis = -1;
}
if (GUI.RepeatButton(new Rect(60,550,50,30),"Right"))
{
hAxis = 1;
}
// Do something with hAxis
Debug.Log("Debug statements shouldn't go in Update functions, but the hAxis value is : " + hAxis);
}
Your answer
Follow this Question
Related Questions
GUI Button for android? 1 Answer
GUI Button Disappears 1 Answer
GUI Repeat Button problem 1 Answer
Hide/show GUI Buion 1 Answer