How do I delay an Ad?

So I have have a script that plays an add every 90 seconds. Every time you change scene (which is quite regular) An ad pops up.

Does anyone know how to delay this

Script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Advertisements;
 
 public class ShowAds : MonoBehaviour
 {
     float timer;
     void Start()
     {
         Advertisement.Initialize ("<YOUR GAME ID HERE>"); //REMEMBER TO EDIT!!
     }
 
     void Update()
     {
         timer -= Time.deltaTime;
         ShowAd ();
     }
 
     public void ShowAd()
     {
         if (Advertisement.IsReady () && timer <= 0) 
         {
             Advertisement.Show ();
             timer = 90.0f;
         }
     }
 }

@chesterhilly You can use Time.time % 90 == 0 as the condition. Using Time.time (notice “…since the start of the game” so it shouldn’t be affected by scene changes) and the modulo operator.

My example will make it so the ad is displayed every 90 seconds, regardless of scene change (sine Time.time should be “since the start of the game” and not since the start of the scene, there will be no reset.

If you definitely don’t want to show an Ad in the beginning of a scene you can use another check Time.timeSinceLevelLoad > 60f (time.timeSinceLevelLoad) this would only show the ad if 60 seconds or more have passed since the scene was loaded.

Now just combine these examples into one if-statement :slight_smile:

The final code would look something like:

      public void ShowAd()
      {
          if (Time.time % 90 == 0 && Time.timeSinceLevelLoad > 60) //Is the time divisible by 90 with no remainder? Has atleast 60 seconds passed since the scene was loaded?
          {
              Advertisement.Show ();
          }
      }

you can simply use Invoke(“ShowAd”, 5f), this will show th ad after 5 seconds (or change it on your needs)