Search Unity

Pause button doesn't work in Android Build, but does in Editor and Remote

Discussion in 'Editor & General Support' started by maddieScarbrough, Sep 10, 2019.

  1. maddieScarbrough

    maddieScarbrough

    Joined:
    Sep 7, 2016
    Posts:
    21
    Hi, I've been working on a 2D mobile game for some time, and I've been getting very frustrated over the pause button not working. If you need the code, here it is:
    Code (CSharp):
    1. // This is under a Game Manager script.
    2. public void PauseTrigger() {
    3.         if (!pausePanel.activeSelf)
    4.         {
    5.             Time.timeScale = 0;
    6.             pausePanel.SetActive(true);
    7.             //Disable scripts that still work while timescale is set to 0
    8.             foreach (GameManager manager in FindObjectsOfType<GameManager>()) {
    9.                 manager.enabled = false;
    10.             }
    11.             foreach (FollowMouse follow in FindObjectsOfType<FollowMouse>()) {
    12.                 follow.enabled = false;
    13.             }
    14.             if (FindObjectsOfType<CannonAimAndFire>() != null)
    15.             {
    16.                 foreach (CannonAimAndFire aimAndFire in FindObjectsOfType<CannonAimAndFire>()) {
    17.                     aimAndFire.enabled = false;
    18.                 }
    19.             }
    20.             if (FindObjectsOfType<EnemyBehaviour>() != null)
    21.             {
    22.                 foreach (EnemyBehaviour enemy in FindObjectsOfType<EnemyBehaviour>())
    23.                 {
    24.                     enemy.enabled = false;
    25.                 }
    26.             }
    27.             Cursor.visible = true;
    28.         } else {
    29.             Time.timeScale = 1;
    30.             pausePanel.SetActive(false);
    31.             //enable the scripts again
    32.             foreach (GameManager manager in FindObjectsOfType<GameManager>()) {
    33.                 manager.enabled = true;
    34.             }
    35.             foreach (FollowMouse follow in FindObjectsOfType<FollowMouse>()) {
    36.                 follow.enabled = true;
    37.             }
    38.             if (FindObjectsOfType<CannonAimAndFire>() != null)
    39.             {
    40.                 foreach (CannonAimAndFire aimAndFire in FindObjectsOfType<CannonAimAndFire>()) {
    41.                     aimAndFire.enabled = true;
    42.                 }
    43.             }
    44.             if (FindObjectsOfType<EnemyBehaviour>() != null)
    45.             {
    46.                 foreach (EnemyBehaviour enemy in FindObjectsOfType<EnemyBehaviour>())
    47.                 {
    48.                     enemy.enabled = true;
    49.                 }
    50.             }
    51.             Cursor.visible = false;
    52.         }
    53.     }
    I set the button's OnClick() event to trigger the PauseTrigger() function in the above code, and it works just fine in the Editor and Unity Remote 5, but it doesn't work at all in the build. I have tried looking around in the forums, and the only solution I've found is to restart Unity because of problems with tags, but I don't use any tags. Any help will be greatly appreciated!
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    A simple trick to figure out how far your code is running before not doing what it should is to add Debug.Log() messages in diefferent places.
    Then you can use logcat to get the logs from your device.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yep, just put Debug.Log messages everywhere and you'll immediately see what code path it is taking or not taking. Also check log messages, as a runtime null reference error is a common cause of the rest of a method not executing (if that is the case, you add more Debug.Log messages to figure out what is null if it isn't immediately obvious).
     
    maddieScarbrough likes this.
  4. maddieScarbrough

    maddieScarbrough

    Joined:
    Sep 7, 2016
    Posts:
    21
    Total noob question: how do you set up Logcat? I don't understand what the docs say about it :/
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. maddieScarbrough

    maddieScarbrough

    Joined:
    Sep 7, 2016
    Posts:
    21