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

Unity Admob Interstitial shows errors?

$
0
0
I found this code on Youtube and was planning to study it. Thing is, the interstitial segment shows errors. I removed the interstitial parts and the code shows no more errors. I will paste the entire thing in case it helps someone else. The link to the Youtube vid is here: [Link][1] using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds.Api; using System; using UnityEngine.UI; using UnityEngine.SceneManagement; public class Admobs : MonoBehaviour { public Text adStatus; string App_ID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; string Banner_AD_ID = "ca-app-pub-3940256099942544/6300978111"; string Interstitial_AD_ID = "ca-app-pub-3940256099942544/1033173712"; string Video_AD_ID = "ca-app-pub-3940256099942544/5224354917"; private BannerView bannerView; private InterstitialAd interstital; private RewardBasedVideoAd rewardBasedVideo; public string Banner_AD_ID1 { get => Banner_AD_ID2; set => Banner_AD_ID2 = value; } public string Banner_AD_ID2 { get => Banner_AD_ID; set => Banner_AD_ID = value; } void Start() { MobileAds.Initialize(App_ID); } private void RequestBanner() { // Create a 320x50 banner at the top of the screen. this.bannerView = new BannerView(Banner_AD_ID, AdSize.Banner, AdPosition.Bottom); // Called when an ad request has successfully loaded. this.bannerView.OnAdLoaded += this.HandleOnAdLoaded; // Called when an ad request failed to load. this.bannerView.OnAdFailedToLoad += this.HandleOnAdFailedToLoad; // Called when an ad is clicked. this.bannerView.OnAdOpening += this.HandleOnAdOpened; // Called when the user returned from the app after an ad click. this.bannerView.OnAdClosed += this.HandleOnAdClosed; // Called when the ad click caused the user to leave the application. this.bannerView.OnAdLeavingApplication += this.HandleOnAdLeavingApplication; } public void ShowBannerAD() { // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. this.bannerView.LoadAd(request); } public void RequestInterstitial() { // Initialize an InterstitialAd. this.interstitial = new InterstitialAd(Interstitial_AD_ID); // Called when an ad request has successfully loaded. this.interstitial.OnAdLoaded += HandleOnAdLoaded; // Called when an ad request failed to load. this.interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad; // Called when an ad is shown. this.interstitial.OnAdOpening += HandleOnAdOpened; // Called when the ad is closed. this.interstitial.OnAdClosed += HandleOnAdClosed; // Called when the ad click caused the user to leave the application. this.interstitial.OnAdLeavingApplication += HandleOnAdLeavingApplication; AdRequest request = new AdRequest.Builder().Build(); this.interstital.LoadAd(request); } public void ShowInterstitialAd() { if (this.interstitial.IsLoaded()) { this.interstitial.Show(); } } public void RequestRewardBasedVideo() { rewardBasedVideo = RewardBasedVideoAd.Instance; // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the rewarded video ad with the request. this.rewardBasedVideo.LoadAd(request, Video_AD_ID); } public void ShowVideoRewardAd() { if (rewardBasedVideo.IsLoaded()) { rewardBasedVideo.Show(); } } // FOR EVENTS AND DELEGATES FOR ADS public void HandleOnAdLoaded(object sender, EventArgs args) { adStatus.text = "Ad Loaded"; if (this.interstitial.IsLoaded()) { this.interstitial.Show(); } } public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) { adStatus.text = "Ad Failed To Load"; } public void HandleOnAdOpened(object sender, EventArgs args) { MonoBehaviour.print("HandleAdOpened event received"); } public void HandleOnAdClosed(object sender, EventArgs args) { MonoBehaviour.print("HandleAdClosed event received"); } public void HandleOnAdLeavingApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleAdLeavingApplication event received"); } } [1]: https://www.youtube.com/watch?v=fGMFHN3gXpY

Viewing all articles
Browse latest Browse all 1416

Trending Articles



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