0

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!!!

BogadoDiego
  • 329
  • 3
  • 7

1 Answers1

2

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(){
        changeState();
    }
    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

Jeff Hornby
  • 12,948
  • 4
  • 40
  • 61
Adam Roszyk
  • 389
  • 1
  • 10