Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by domistn · Jul 11, 2019 at 01:38 PM · erroradsadmob

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

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<SaveColor>().StoreChanges();/*
         if (rewardBasedVideo.IsLoaded()) {
             hasSeenRBV = false;
             rewardBasedVideo.Show();
             if(hasSeenRBV) {
                 if(whatToDo == 1) {
                     GetComponent<SaveColor>().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<SaveColor>().StoreChanges();
     }
 }
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot add menu item 'Assets/External Dependency Manager/Version Handler/Update' for method ..... 1 Answer

I can't use google admob ads 1 Answer

mobclix plugin issue for windows 1 Answer

Unrecognized Attribute name MODULE when building .AAB with AdMob 2 Answers

iAds fallback to admob 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges