0
\$\begingroup\$

There is an NGUI button in my game, which when pressed increases the player's power.

When I press the escape key, my game pauses completely. But the button still functions normally. Here's how I check for pausing:

void Update () 
{       
    if(Input.GetKeyDown("escape"))     
    {
        if(isPaused && Time.timeScale == 1.0f){
            Time.timeScale = 0.0f;
            AudioListener.volume = 1;
        }       
        else
        {
            Time.timeScale = 1.0f;  
            AudioListener.volume = 0;
        }
    }
}

I'd like the button to be deactivated when the game is paused. It should be visible, but not be clickable or anything. How can I achieve that?

\$\endgroup\$
  • \$\begingroup\$ What do you mean by "disable?" Do you want to change the button's appearance? Or just make clicking it do nothing? What have you tried? Can you not just query whether your game is paused in the click handler and early out? Et cetera. \$\endgroup\$ – Josh Dec 3 '14 at 18:36
1
\$\begingroup\$

Just set isEnabled of the desired UIButton to false. This will just disable it's collider, and it will still be visible. :-)

\$\endgroup\$
0
\$\begingroup\$

I'd imagine the simplest way would be to give the Script that accesses the button knowledge about isPaused. Some type of static access would make sense to me in this case, since multiple scripts might need to change their behaviour based on the value of isPaused.

public class ButtonBehaviour : MonoBehaviour {

....

public void onPress() {
    if (!PauserClass.isPaused) {
        makePlayerStronger(); 
    }
}

....

}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.