Quantcast
Channel: Questions in topic: "ads"
Viewing all articles
Browse latest Browse all 1416

How to display AdMob interstitial on button click?

$
0
0
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(); }

Viewing all articles
Browse latest Browse all 1416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>