Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED][ADMOB] is absolete use interstitialeAd.Load()

Discussion in 'Getting Started' started by madara5555, Jan 24, 2023.

  1. madara5555

    madara5555

    Joined:
    May 4, 2021
    Posts:
    8
    NOTE : This exist in GoogleMobileAds-v7.4.0.unitypackage or above

    Google Mobile Ads Unity Plugin
    Changes 2023

    There are ways to call ads that were changed in 2023
    Some operations have been cancelled
    also changed (adRequest)

    interstitialAd = new InterstitialAd(adUnitId); cancled
    interstitialAd.LoadAd(CreateAdRequest()); cancled

    PROBLEMS:

    'InterstitialAd.InterstitialAd(string)' is absolete 'Use InterstitialAd.Load().'

    more info about errors:
    Not work admob on scene
    warning+CS0618
    plugin ads error 2023
    adRequest not work
    use InterstitialAd.Load()



    SOLUTION:
    1-Request
    Code (CSharp):
    1.  
    2. private InterstitialAd interstitial;
    3.    public string adUnitId;
    4.  
    5.    private void RequestInterstitial()
    6.    {
    7.        adUnitId = "ca-app-pub-3940256099942544/1033173712"; // test id
    8.  
    9.        // Clean up interstitial before using it
    10.        if (interstitial != null)
    11.        {
    12.            interstitial.Destroy();
    13.        }
    14.  
    15.        AdRequest request = new AdRequest.Builder().Build();
    16.        InterstitialAd.Load(adUnitId, request, (InterstitialAd ad, LoadAdError loadAdError) =>
    17.        {
    18.            if (loadAdError != null)
    19.            {
    20.                return;
    21.            }
    22.            else
    23.            if (ad == null)
    24.            {
    25.                return;
    26.            }
    27.            Debug.Log("Interstitial ad loaded");
    28.            interstitial = ad;
    29.  
    30.        });
    31.    }
    32.  
    2- Show
    Code (CSharp):
    1. public void ShowInterstitialAd()  // Show
    2.    {
    3.        if (interstitial != null && interstitial.CanShowAd())
    4.        {
    5.            interstitial.Show();
    6.        }
    7.    }
    8.  

    Cheak if user close ad

    Example:

    Code (CSharp):
    1. private InterstitialAd interstitial;
    2.     public string adUnitId;
    3.  
    4.     private void RequestInterstitial()
    5.     {
    6.         adUnitId = "ca-app-pub-3940256099942544/1033173712"; // test id
    7.  
    8.         // Clean up interstitial before using it
    9.         if (interstitial != null)
    10.         {
    11.             interstitial.Destroy();
    12.         }
    13.  
    14.         AdRequest request = new AdRequest.Builder().Build();
    15.         InterstitialAd.Load(adUnitId, request, (InterstitialAd ad, LoadAdError loadAdError) =>
    16.         {
    17.             if (loadAdError != null)
    18.             {
    19.                 return;
    20.             }
    21.             else
    22.             if (ad == null)
    23.             {
    24.                 return;
    25.             }
    26.             Debug.Log("Interstitial ad loaded");
    27.             interstitial = ad;
    28.  
    29.             ad.OnAdFullScreenContentClosed += HandleOnAdFullScreenContentClosed;   //  >>>> HERE <<<<
    30.  
    31.         });
    32.  
    33.     }
    34.     public void HandleOnAdFullScreenContentClosed()
    35.     {
    36.         Debug.Log("Interstitial ad Closed");
    37.     }





    sample Project from google : https://github.com/googleads/googleads-mobile-unity/tree/main/samples
    moro info :https://github.com/googleads/googleads-mobile-unity/releases/tag/v7.4.0
     
    Last edited: Feb 3, 2023
    Luucccc, AlterMannn and kevinksmith like this.
  2. mamafielsar3456

    mamafielsar3456

    Joined:
    Jul 25, 2022
    Posts:
    1
    Thank you brother. How to find this solution for rewarded ads ?
     
  3. madara5555

    madara5555

    Joined:
    May 4, 2021
    Posts:
    8
    by webside > Github