0

I'm making a pause button for a game that will enable a game object and its children when the user clicks a certain rectangle (initially they're disabled). However, whenever I click the rectangle, nothing happens and I can't seem to figure out why. Here's my code:

void Update () {
    if (Input.GetMouseButtonDown (0)) {
        if (buttonRect.Contains (Input.mousePosition)) {
            Time.timeScale = 0.0f;
            PauseScreen.gameObject.SetActive (true);
        } else {
            Debug.Log("Else");
        }
    }
}

Thanks for any answers!

Programmer
  • 121,791
  • 22
  • 236
  • 328
banachbegone
  • 46
  • 1
  • 9
  • Likely one of two things: either a) the rectangle does not contain the mouse position for some reason (you'll have to debug) or b) it works once (the game pauses, but never unpauses) because TimeScale of 0 means that `Update()` *never fires again.* – Draco18s no longer trusts SE Jan 07 '18 at 08:02
  • That's not how to detect clicks on Objects. I don't know the type of object you are working with (UI, 2D or 3D) but see the duplicate for how to detect click on any object. – Programmer Jan 07 '18 at 08:10

0 Answers0