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 lochiamavanosviluppatore · Nov 19, 2017 at 03:24 PM · uiadsadmob

There are ad request but the ads not showing..

The ads are not showing, I think because there are off the screen.. But I can't figure oute the problem. Hope there is the right section and sorry for the bad English.

Under the MenuAds

 using System;
 using UnityEngine;
 using GoogleMobileAds;
 using GoogleMobileAds.Api;
 
 public class MenuAds : MonoBehaviour {
 
     private BannerView bannerView;
     private InterstitialAd interstitial;
     private NativeExpressAdView nativeExpressAdView;
 
     public void Start()
     {
 
 #if UNITY_ANDROID
         string appId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_IPHONE
         string appId = "ca-app-pub-9369507388231074/5771936825";
 #else
         string appId = "unexpected_platform";
 #endif
 
         // Initialize the Google Mobile Ads SDK.
         MobileAds.Initialize(appId);
     }
 
     private AdRequest CreateAdRequest()
     {
         return new AdRequest.Builder()
             .AddTestDevice(AdRequest.TestDeviceSimulator)
             .AddKeyword("game")
             .SetGender(Gender.Male)
             .SetBirthday(new DateTime(1985, 1, 1))
             .TagForChildDirectedTreatment(false)
             .AddExtra("color_bg", "9B30FF")
             .Build();
     }
 
     private void DestroyBanner()
     {
         // Clean up banner ad before creating a new one.
         if (this.bannerView != null)
         {
             this.bannerView.Destroy();
         }
     }
 
     private void DestroyNative()
     {
         // Clean up interstitial ad before creating a new one.
         if (this.interstitial != null)
         {
             this.interstitial.Destroy();
         }
     }
 
     public void RequestBanner()
     {
         // These ad units are configured to always serve test ads.
 #if UNITY_EDITOR
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_ANDROID
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_IPHONE
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #else
         string adUnitId = "unexpected_platform";
 #endif
 
         // Clean up banner ad before creating a new one.
         if (this.bannerView != null)
         {
             this.bannerView.Destroy();
         }
 
         // Create a 320x50 banner at the top of the screen.
         this.bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
 
         // Register for ad events.
         this.bannerView.OnAdLoaded += this.HandleAdLoaded;
         this.bannerView.OnAdFailedToLoad += this.HandleAdFailedToLoad;
         this.bannerView.OnAdOpening += this.HandleAdOpened;
         this.bannerView.OnAdClosed += this.HandleAdClosed;
         this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;
 
         // Load a banner ad.
         this.bannerView.LoadAd(this.CreateAdRequest());
         this.bannerView.Show();
     }
 
     public void RequestInterstitial()
     {
         // These ad units are configured to always serve test ads.
 #if UNITY_EDITOR
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_ANDROID
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_IPHONE
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #else
         string adUnitId = "unexpected_platform";
 #endif
 
         // 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.
         this.interstitial.LoadAd(this.CreateAdRequest());
     }
 
     public void RequestNativeExpressAdView()
     {
         // These ad units are configured to always serve test ads.
 #if UNITY_EDITOR
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_ANDROID
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #elif UNITY_IPHONE
         string adUnitId = "ca-app-pub-9369507388231074/5771936825";
 #else
         string adUnitId = "unexpected_platform";
 #endif
 
         // Clean up native express ad before creating a new one.
         if (this.nativeExpressAdView != null)
         {
             this.nativeExpressAdView.Destroy();
         }
 
         // Create a 320x150 native express ad at the top of the screen.
         this.nativeExpressAdView = new NativeExpressAdView(
             adUnitId,
             new AdSize(320, 150),
             AdPosition.Top);
 
         // Register for ad events.
         this.nativeExpressAdView.OnAdLoaded += this.HandleNativeExpressAdLoaded;
         this.nativeExpressAdView.OnAdFailedToLoad += this.HandleNativeExpresseAdFailedToLoad;
         this.nativeExpressAdView.OnAdOpening += this.HandleNativeExpressAdOpened;
         this.nativeExpressAdView.OnAdClosed += this.HandleNativeExpressAdClosed;
         this.nativeExpressAdView.OnAdLeavingApplication += this.HandleNativeExpressAdLeftApplication;
 
         // Load a native express ad.
         this.nativeExpressAdView.LoadAd(this.CreateAdRequest());
         this.nativeExpressAdView.Show();
     }
 
     public void ShowInterstitial()
     {
         if (this.interstitial.IsLoaded())
         {
             this.interstitial.Show();
         }
         else
         {
             MonoBehaviour.print("Interstitial is not ready yet");
         }
     }
 
     #region Banner callback handlers
 
     public void HandleAdLoaded(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleAdLoaded event received");
     }
 
     public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         MonoBehaviour.print("HandleFailedToReceiveAd event received with message: " + args.Message);
     }
 
     public void HandleAdOpened(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleAdOpened event received");
     }
 
     public void HandleAdClosed(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleAdClosed event received");
     }
 
     public void HandleAdLeftApplication(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleAdLeftApplication event received");
     }
 
     #endregion
 
     #region Interstitial callback handlers
 
     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");
     }
 
     #endregion
 
     #region Native express ad callback handlers
 
     public void HandleNativeExpressAdLoaded(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleNativeExpressAdAdLoaded event received");
     }
 
     public void HandleNativeExpresseAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         MonoBehaviour.print(
             "HandleNativeExpressAdFailedToReceiveAd event received with message: " + args.Message);
     }
 
     public void HandleNativeExpressAdOpened(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleNativeExpressAdAdOpened event received");
     }
 
     public void HandleNativeExpressAdClosed(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleNativeExpressAdAdClosed event received");
     }
 
     public void HandleNativeExpressAdLeftApplication(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleNativeExpressAdAdLeftApplication event received");
     }
 
     #endregion
 }


Under the GameManager

     void Vittoria()
     {
         if (score1 == 5)
         {
             panel.SetActive(true);
             Exit.SetActive(true);
             ExitB.SetActive(true);
             player1Won.SetActive(true);
 
             vittoria = true;
 
             GameObject go = GameObject.Find("MainCamera");
             //MenuAds ads = (MenuAds)go.GetComponent(typeof(MenuAds));
             MenuAds ads = go.GetComponent<MenuAds>();
             ads.RequestNativeExpressAdView();
         }
         if (score2 == 5)
         {
             panel.SetActive(true);
             Exit.SetActive(true);
             ExitB.SetActive(true);
             player2Won.SetActive(true);
 
             vittoria = true;
 
             GameObject go = GameObject.Find("MainCamera");
             //MenuAds ads = (MenuAds)go.GetComponent(typeof(MenuAds));
             MenuAds ads = go.GetComponent<MenuAds>();
             ads.RequestNativeExpressAdView();
         }
     }

Under the MenuAdsScript

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MenuAdsScript : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
 
         GameObject go = GameObject.Find("MainCamera");
         MenuAds ads = (MenuAds)go.GetComponent(typeof(MenuAds));
         ads.RequestBanner();
 
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 }
 

The console message

alt text

catturdsfa.png (138.1 kB)
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

122 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

Related Questions

AdMob RewardBasedVideoAd, App crash after reward video closed (Android) 5 Answers

Admob don' t show ads, only request it 0 Answers

google ad mob display ad on canvas 0 Answers

admob interstitial not showing correctly 0 Answers

Admob rewarded videos not rewarding 1 Answer


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