Hi there, I'm making an android game and I want AdMob's interstitial ad to be displayed when a button is clicked in different scenes. I have added below code in a scenes button script and I'm using the same code in every scene's button script. I don't know that if it'll work or even if it's correct. On play It does not displays or give any errors. Is it correct or not?
P.S: The adUnitId is for test ads.
public void sceneOneButton()
{
RequestInterstitial();
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex +1);
}
private void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an InterstitialAd.
InterstitialAd interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
// Show the interstitial.
interstitial.Show();
}
↧