- Home /
How to Disable GUI Button Immediately After Click
What I want to have is how can I immediately disable the GUI button when I click it so that it will not trigger another another attack function.
Here's my code: void OnGUI()
{
...
battleQ = GUI.Window(2, battleQ, battleWin,"Tasyo",battleSkin.window);
}
void battleWin (int winID)
{
...
if (slash == true)
GUI.enabled = true; // enables the GUI button to make attack
else
GUI.enabled = false;
if(GUI.Button(AttackB,">"))
{
slash = false;
GUI.enabled = false;
//player attack
if (atake == true)
{
bida.transform.position = new Vector3(319,10,271);
playerAnim.SetBool("idle2ToIdle1", true);
}
else
{
playerAnim.SetBool("idle2ToIdle0", true);
}...
What happen is, when I click the GUI.button. it does the animation, but the button is still active. This give a enables the Gui button to be clicked again even if the execution of animation and some functions are not done. And when it does, It jams the battle system. The GUI.button only disable when it's done executing the code.. if I'm not mistaken.
Thanks in advance
Answer by Sisso · Feb 25, 2014 at 08:38 PM
If you don't want to show a Gui element, don't call it.
if(showAttackButton && GUI.Button(AttackB,">")) {
showAttackButton = false;
}
Your answer

Follow this Question
Related Questions
Hide GUI while switchcam 3 Answers
disable all weapons for 5 seconds 1 Answer
Disabling collsions between MeshColliders and bullets 2 Answers
Disable Unity audio/FMOD on iOS 0 Answers