Shrikrishna Joisa Shrikrishna Joisa - 1 year ago 149
C# Question

How to combine pause and unpause game button in unity [C#] with GUI?

I am working on a Unity C# game and I want my pause button to be GUI [with the pause and unpause image displayed on click].

Any help would be great.Thank you so much!!!

Answer Source

The easiest way is to create new Button object, and add proper method for displaying correct image. Something like this:

public class ButtonStateHandler:MonoBehaviour
    public bool isClicked;
    public Button myBtn;
    public Sprite Play;
    public Sprite Pause;

    public void Click(){
    private void changeState(){
        isClicked = !isClicked;
        if(isClicked)       myBtn.image.sprite = Play;
        else myBtn.image.sprite = Pause;

And then remember to add Click method in the inspector to OnClick list on Play/Pause button.

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download