Search Unity

Close the ad before changing the scene

Discussion in 'Multiplayer' started by MaciejKusztal, Nov 25, 2020.

?

How can I load a scene after closing the ad?

  1. First close ad after load a scene.

    5 vote(s)
    62.5%
  2. First close ad after load a scene.

    5 vote(s)
    62.5%
Multiple votes are allowed.
  1. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    Hello,
    I added to my project AdMob system. I'm using interstitial ads, everything works fine. It works in such a way that after the end of the game, a button appears, which is to load the next scene (the ad appears when you click it), unfortunately the ad appears for about 1 second and the scene is loaded. The user has no time to close the ad. What condition can I use if I want the scene to load only after the ad is closed?
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    There is a callback when the interstitial ad is closed, you can load the next scene in that.
     
  3. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    I found it. Thanks :)
     
    Munchy2007 likes this.
  4. zxnots814108

    zxnots814108

    Joined:
    Jan 1, 2021
    Posts:
    1
    I have the same problem. How should I use the callback function?
     
  5. ManieBesselaar

    ManieBesselaar

    Joined:
    Nov 1, 2018
    Posts:
    30
    Hi
    I was just googling around to solve a similar ad loading issue. I think I can answer your question. When you set up your interstitial ad you can create a callback function for InterstitialAd.OnAdClosed. In this callback you can then load the scene that was going to load when the button was clicked.
    To initiate the ad being shown you can have a public function that gets called with the name of the scene to load as a param. Keep this as a string in your admanager and then call interstitial.show (providing you loaded the ad... etc).
    then when the onAdClosed callback occurs just call your scenemanager and load the intended scene.

    Just remember to use the ad failure call backs to cover your bases so that the app does not get stuck if the ad fails to show for some reason.
    Ironically writing it out has just helped me solve my own problem. :)

    Hope this helps you, or maybe someone else in future.

    Edit: someone asked me for more detail. Did a quick example at https://forum.unity.com/conversations/about-interstitialad-onadclosed.597485/#message-1191263
    The code is far from complete but should convey the idea. Corrections and comments welcome.
     
    Last edited: Apr 26, 2022
    arom72904 likes this.
  6. arom72904

    arom72904

    Joined:
    Jan 26, 2019
    Posts:
    1
    Thank you so much you helped me
     
  7. ManieBesselaar

    ManieBesselaar

    Joined:
    Nov 1, 2018
    Posts:
    30
    Glad to hear!