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
private InterstitialAd interstitial;
public string adUnitId;
private void RequestInterstitial()
{
adUnitId = "ca-app-pub-3940256099942544/1033173712"; // test id
// Clean up interstitial before using it
if (interstitial != null)
{
interstitial.Destroy();
}
AdRequest request = new AdRequest.Builder().Build();
InterstitialAd.Load(adUnitId, request, (InterstitialAd ad, LoadAdError loadAdError) =>
{
if (loadAdError != null)
{
return;
}
else
if (ad == null)
{
return;
}
Debug.Log("Interstitial ad loaded");
interstitial = ad;
});
}
2- Show
public void ShowInterstitialAd() // Show
{
if (interstitial != null && interstitial.CanShowAd())
{
interstitial.Show();
}
}
Cheak if user close ad
Example:
private InterstitialAd interstitial;
public string adUnitId;
private void RequestInterstitial()
{
adUnitId = "ca-app-pub-3940256099942544/1033173712"; // test id
// Clean up interstitial before using it
if (interstitial != null)
{
interstitial.Destroy();
}
AdRequest request = new AdRequest.Builder().Build();
InterstitialAd.Load(adUnitId, request, (InterstitialAd ad, LoadAdError loadAdError) =>
{
if (loadAdError != null)
{
return;
}
else
if (ad == null)
{
return;
}
Debug.Log("Interstitial ad loaded");
interstitial = ad;
ad.OnAdFullScreenContentClosed += HandleOnAdFullScreenContentClosed; // >>>> HERE <<<<
});
}
public void HandleOnAdFullScreenContentClosed()
{
Debug.Log("Interstitial ad Closed");
}
sample Project from google : googleads-mobile-unity/samples at main · googleads/googleads-mobile-unity · GitHub
moro info :Release Google Mobile Ads Unity Plugin v7.4.0 · googleads/googleads-mobile-unity · GitHub