- Home /
GUI Button Disappears
Hello, I'm trying to make left and right GUI buttons for my character. But when ever the left button is pressed, the right button disappears. The right button works correctly.
I figure it's because once the left button conditional statement is started, the if statement that shows the right is no longer activated. Any combination of if/else if statements don't seem to work.
Here's my code:
var theMainCharacter : GameObject;
function OnGUI () {
if (GUI.RepeatButton(Rect (0,Screen.height - 50,100,50), "Left")) {
theMainCharacter.animation.CrossFade ("walk");
}
else{
if (GUI.RepeatButton(Rect (100,Screen.height-50,100,50), "Right")) {
theMainCharacter.animation.CrossFade ("walk");
}
else{
theMainCharacter.animation.CrossFade ("idle");
}
}
}
Answer by deadfire56 · Jun 28, 2011 at 02:55 PM
Solved it on my own!
I just seperated the if statement from the one that creates the object:
var theMainCharacter : GameObject;
function OnGUI () {
var leftButton = GUI.RepeatButton(Rect (0,Screen.height - 50,100,50), "Left");
var rightButton = GUI.RepeatButton(Rect (100,Screen.height-50,100,50), "Right");
if (leftButton) {
theMainCharacter.animation.CrossFade ("walk");
}
else if (rightButton) {
theMainCharacter.animation.CrossFade ("walk");
}
else{
theMainCharacter.animation.CrossFade ("idle");
}
}
Your answer
Follow this Question
Related Questions
Hide/show GUI Buion 1 Answer
GUI & GUI Text Disappear When Publishing 6 Answers
how can i make my GUI disapear after i pressed a button? 2 Answers
[C#] Read from a file and write in a button? 1 Answer
Centering a texture in a GUI.Button 4 Answers