Pausing Game while Ad Plays

Hi All,

I’m having an issue with my game not pausing when an ad plays. The ad pops up every 3rd time the player restarts. I’ve read on some forms (these were all a year or two old) that the Unity Ad does not automatically pause the game when an ad pops up when using the editor, but it will auto pause in the final build on mobile. Is this still true?

If not, what do I do to pause/unpause the game when an ad is showing? I have it pausing, but can’t figure out how to unpause it after the user closes the ad.

    public void AdControl ()
    {
        DataManagement.datamanagement.loadSceneCount++;
        Debug.Log ("Load Scene Count +1");

        if (Advertisement.IsReady() && DataManagement.datamanagement.loadSceneCount >= DataManagement.datamanagement.adFrequency)
        {
            Advertisement.Show();
            Debug.Log ("ad shown");
            DataManagement.datamanagement.loadSceneCount -= DataManagement.datamanagement.adFrequency;
            Time.timeScale = 0;                                        //pause here
            GetComponent<DistanceCalculator> ().enabled = false;    //stops score from calculating
        }
        DataManagement.datamanagement.SaveData ();
    }

Thanks in advance! :slight_smile:

PS. I do need to pause the DistanceCalculator when the ad is playing and start it back up when the ad finishes. How do I do this?

time.TimeScale = 1f;

Or try… Corrected

 public void AdControl ()
    {
        DataManagement.datamanagement.loadSceneCount++;
        Debug.Log ("Load Scene Count +1");
        if (Advertisement.IsReady() && DataManagement.datamanagement.loadSceneCount >= DataManagement.datamanagement.adFrequency)
        {
            Advertisement.Show();
            Debug.Log ("ad shown");
            DataManagement.datamanagement.loadSceneCount -= DataManagement.datamanagement.adFrequency;
            Time.timeScale = 0;                                        //pause here
            GetComponent<DistanceCalculator> ().enabled = false;    //stops score from calculating
        } else
               {
                   Time.timeScale = 1f;
                   GetComponent<DistanceCalculator>().enabled =true;
               }
        DataManagement.datamanagement.SaveData ();
    }
2 Likes

Corrected the script to enable distance calculator. Let me know if that helps.

First off, thanks for the help! :slight_smile:

When I put in the else statement, the ad actually never shows and the line,

DataManagement.datamanagement.loadSceneCount++;

doesn’t seem to be running because the loadSceneCount never goes up.

Should there be a separate scene for the ad to show in and then when the player closes the ad, it reloads (restarts) the game scene? (This ad is currently showing every 3rd time after the player hits the restart button at the end of the game)

1 Like

What package are you using to do your ads. It should have statements to where you can do something like this…

public void AdControl ()
    {
        DataManagement.datamanagement.loadSceneCount++;
        Debug.Log ("Load Scene Count +1");
        if (Advertisement.IsReady() && DataManagement.datamanagement.loadSceneCount >= DataManagement.datamanagement.adFrequency)
        {
            Advertisement.Show();
            Debug.Log ("ad shown");
            DataManagement.datamanagement.loadSceneCount -= DataManagement.datamanagement.adFrequency;
            Time.timeScale = 0;                                        //pause here
            GetComponent<DistanceCalculator> ().enabled = false;    //stops score from calculating
      
          } else if (Advertisement.IsNotReady)
         {
           Advertisement.Hide();
          Debug.Log ("ad not shown");
          Time.timeScale = 1;                                      
          GetComponent<DistanceCalculator> ().enabled = true;
        }
        DataManagement.datamanagement.SaveData ();
    }
1 Like

And no your ads should show up anywhere at anytime. There are some ad packages that you have to specify where the ad is showing. Like in main scene, scene1, etc… Thats why i asked what package your using for ads. But youd of seen that within the guide that came with those certain packages. But, there should still be statements like isnotready that you can call on to not show the ad

And no your ads should show up anywhere at anytime. There are some ad packages that you have to specify where the ad is showing. Like in main scene, scene1, etc… Thats why i asked what package your using for ads. But youd of seen that within the guide that came with those certain packages. But, there should still be statements like isnotready that you can call on to not show the ad

I’m using Unity Ads for this specific ad.

It doesn’t seem like Unity Ads has anything like Advertisement.Hide (); or isnotready, unless I’m mistaken.

Also, I made a quick test build for my phone and the Unity Ad never even shows up. Is this because the game has to be officially published to the app/play store for it to get an ad to play for the user?

Well unity uses a search engine to find your app/game within the market. But you should be able to show the default ad screen inside your app/game. Does the ads show at all with your original code? Here’s some info I found… How do I pause the game while the ads are showing - Unity Services - Unity Discussions it seems the game will automatically pause when the ad is shown. So I would try it without timescale set to 0. Maybe bybyou pausing it yourself in code that’s causing the ad to pause completely and not show…