Search Unity

How do I pause the game while the ads are showing

Discussion in 'Unity Ads & User Acquisition' started by IDontCare85060, Jun 11, 2015.

  1. IDontCare85060

    IDontCare85060

    Joined:
    Jan 23, 2015
    Posts:
    28
    I was wondering how i can pause my game while the ads are showing
     
  2. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Your game should automatically be paused while the video ad is shown. Please provide some information about which version of SDK you are using, and if possible some code that shows how you show the ad.

    /Rasmus
     
  3. M.O.

    M.O.

    Joined:
    May 30, 2013
    Posts:
    4
    You can just stop executing your game logic, or depending on how you have things set up, adjust Time.timescale
     
  4. IDontCare85060

    IDontCare85060

    Joined:
    Jan 23, 2015
    Posts:
    28
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class RestartGameScript : MonoBehaviour {
    6.  
    7.     public GameObject restartButton;
    8.  
    9.     void Start()
    10.     {
    11.         Advertisement.Initialize ("42968", true);
    12.      
    13.         StartCoroutine (ShowAdWhenReady());
    14.      
    15.     }
    16.  
    17.     IEnumerator ShowAdWhenReady ()
    18.     {
    19.         while (!Advertisement.isReady())
    20.             yield return null;
    21.      
    22.         Advertisement.Show ();
    23.     }
    24.  
    25.  
    26.     public void RestartGame () {
    27.         {
    28.             Application.LoadLevel (Application.loadedLevel);      
    29.         }
    30.     }
    31. }
    I used this so i can have the ad show when it restarts, also I believe i have version 1.1.4.
     
    Last edited: Jun 13, 2015
  5. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    When running your app on device, the Unity Player will pause while Unity Ads are shown. However, if you are testing in the Unity Editor, the game is not paused while the placeholder ads are shown.

    You could handle this by pausing audio playback and setting the timescale to 0 while showing. Then un-pause the audio and restore the timescale value after the ad placeholder is closed.

    There used to be pausing functionality in the Unity Editor. This was removed when we removed support for picture ads.
     
  6. dehdar

    dehdar

    Joined:
    Sep 1, 2016
    Posts:
    51
    Wish I had read this 30 minutes ago. I eventually learned by trial and error, even though I'm not supposed to disable test-mode. Sorry :S
     
    MementoMoriGames likes this.
  7. esteban16108

    esteban16108

    Joined:
    Jan 23, 2014
    Posts:
    159
    OK, I lost 2 hours of my life trying to debug why the game wasn't pausing even when I was forcing it to pause setting timescale to 0.

    Good to know.

    Would be nice to add this to the docs tho.

    Thanks.