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

AdMob real ads don't show but test ads work as expected

$
0
0
Hi all, I recently learned how to setup ads on Unity using Admob. I've put my payment details, got a confirmation that my ad serving is enabled and tested with test ads (a banner, an interstitial and a rewarded video ad) and they work perfectly fine. When I replaced the test adUnitId's with mine, built the application and downloaded it to my device, suddenly, the ads stopped appearing. I searched for solutions, but none worked. So, **what could cause this?** Here is my code, attached to my Game Control GameObject: using System; using UnityEngine; using UnityEngine.SceneManagement; using GoogleMobileAds.Api; public class GameControl : MonoBehaviour { bool hasSeenRBV = false; private BannerView bannerView; private InterstitialAd interstitial; private RewardedAd rewardedAd; void Start() { #if UNITY_EDITOR string appId = "unused"; #elif UNITY_ANDROID string appId = "ca-app-pub-thisIsMyCorrect~appId"; #elif UNITY_IPHONE string appId = "unexpected_platform"; #else string appId = "unexpected_platform"; #endif // Initialize the Google Mobile Ads SDK. MobileAds.Initialize(appId); this.RequestBanner(); this.RequestInterstitial(); this.CreateAndLoadRewardedAd(); } private void RequestBanner() { #if UNITY_ANDROID string adUnitId = "ca-app-pub-thisIsTheCorrect~addUnitId"; #elif UNITY_IPHONE string adUnitId = "unexpected_platform"; #else string adUnitId = "unexpected_platform"; #endif //string adUnitId = "ca-app-pub-3940256099942544/6300978111"; - test ads // Create a 320x50 banner at the top of the screen. bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom); // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. bannerView.LoadAd(request); } private void RequestInterstitial() { #if UNITY_ANDROID string adUnitId = "ca-app-pub-thisIsTheCorrect~addUnitId"; #elif UNITY_IPHONE string adUnitId = "unexpected_platform"; #else string adUnitId = "unexpected_platform"; #endif //string adUnitId = "ca-app-pub-3940256099942544/1033173712"; - test ads // Clean up interstitial ad before creating a new one. if (this.interstitial != null) { this.interstitial.Destroy(); } // Create an interstitial. this.interstitial = new InterstitialAd(adUnitId); // Register for ad events. this.interstitial.OnAdLoaded += this.HandleInterstitialLoaded; this.interstitial.OnAdFailedToLoad += this.HandleInterstitialFailedToLoad; this.interstitial.OnAdOpening += this.HandleInterstitialOpened; this.interstitial.OnAdClosed += this.HandleInterstitialClosed; this.interstitial.OnAdLeavingApplication += this.HandleInterstitialLeftApplication; // Load an interstitial ad. AdRequest request = new AdRequest.Builder().Build(); this.interstitial.LoadAd(request); } private void ShowInterstitial() { if (this.interstitial.IsLoaded()) { this.interstitial.Show(); } else { MonoBehaviour.print("Interstitial is not ready yet"); } } public void CreateAndLoadRewardedAd() { #if UNITY_ANDROID string adUnitId = "ca-app-pub-thisIsTheCorrect~addUnitId"; #elif UNITY_IPHONE string adUnitId = "unexpected_platform"; #else string adUnitId = "unexpected_platform"; #endif //string adUnitId = "ca-app-pub-3940256099942544/5224354917"; -- test ads // Create new rewarded ad instance. this.rewardedAd = new RewardedAd(adUnitId); // Called when an ad request has successfully loaded. this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded; // Called when an ad request failed to load. this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad; // Called when an ad is shown. this.rewardedAd.OnAdOpening += HandleRewardedAdOpening; // Called when an ad request failed to show. this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow; // Called when the user should be rewarded for interacting with the ad. this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward; // Called when the ad is closed. this.rewardedAd.OnAdClosed += HandleRewardedAdClosed; // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the rewarded ad with the request. this.rewardedAd.LoadAd(request); } private void ShowRewardedAd() { if (this.rewardedAd.IsLoaded()) { this.rewardedAd.Show(); } else { MonoBehaviour.print("Rewarded ad is not ready yet"); } } public void StartGame() { if(PlayerPrefs.GetInt("tut") == 2) { SceneManager.LoadScene("Game"); } else { PlayerPrefs.SetInt("tut", 2); SceneManager.LoadScene("Tutorial"); } } public void RetryLevel() { int matchesTillLoadAd = PlayerPrefs.GetInt("mtla"); if(matchesTillLoadAd == 3) { this.ShowInterstitial(); } else { SceneManager.LoadScene("Game"); } PlayerPrefs.SetInt("mtla", (matchesTillLoadAd + 1) % 4); //SceneManager.LoadScene("Game"); } public void ToMainMenu() { SceneManager.LoadScene("Menu"); } public void ToSkins() { SceneManager.LoadScene("Skins"); } public void SaveColorByLoadingAd(int whatToDo) { ShowRewardedAd(); /*GetComponent().StoreChanges();/* if (rewardBasedVideo.IsLoaded()) { hasSeenRBV = false; rewardBasedVideo.Show(); if(hasSeenRBV) { if(whatToDo == 1) { GetComponent().StoreChanges(); } } }*/ } public void HandleInterstitialLoaded(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialLoaded event received"); } public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args) { MonoBehaviour.print( "HandleInterstitialFailedToLoad event received with message: " + args.Message); } public void HandleInterstitialOpened(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialOpened event received"); } public void HandleInterstitialClosed(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialClosed event received"); } public void HandleInterstitialLeftApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialLeftApplication event received"); } public void HandleRewardedAdLoaded(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardedAdLoaded event received"); } public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args) { MonoBehaviour.print( "HandleRewardedAdFailedToLoad event received with message: " + args.Message); } public void HandleRewardedAdOpening(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardedAdOpening event received"); } public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args) { MonoBehaviour.print( "HandleRewardedAdFailedToShow event received with message: " + args.Message); } public void HandleRewardedAdClosed(object sender, EventArgs args) { MonoBehaviour.print("HandleRewardedAdClosed event received"); } public void HandleUserEarnedReward(object sender, Reward args) { string type = args.Type; double amount = args.Amount; MonoBehaviour.print( "HandleRewardedAdRewarded event received for " + amount.ToString() + " " + type); GetComponent().StoreChanges(); } }

Viewing all articles
Browse latest Browse all 1416

Trending Articles



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