• 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 sumitss · Jun 24, 2018 at 03:23 PM · errorscript.

cant see my ads when i build the game.....pls help

my ad controller script is bellow everything works fine in editor tried using same app id and other id's in googleadsdemoscript they work there so my id's are working

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using GoogleMobileAds.Api;
 using UnityEngine.SceneManagement;
 using System;
 
 
 
 public class AdController : MonoBehaviour {
 
  public static AdController instance;
 
     private BannerView bannerView;
     private InterstitialAd interstitial;
     private float deltaTime = 0.0f;
     private static string outputMessage = string.Empty;
 
     public static string OutputMessage
     {
         set { outputMessage = value; }
     }
 
     //public InterstitialAd interstitial;
 
     void Awake()
  {
     MakeSingleton();
 
     }
     void Start()
     {
 #if UNITY_ANDROID
         string appId = "************my ap id*********";
 #elif UNITY_IPHONE
         string appId = "";
 #else
         string appId = "unexpected_platform";
 #endif
 
         MobileAds.SetiOSAppPauseOnBackground(true);
 
         // Initialize the Google Mobile Ads SDK.
         MobileAds.Initialize(appId);
        RequestBanner();
        RequestInterstitial();
     }
     void MakeSingleton()
     {
         if (instance != null)
         {
             Destroy(gameObject);
         }
         else
         {
             instance = this;
             DontDestroyOnLoad(gameObject);
         }
     
     }
 
 
     public void Update()
     {
         // Calculate simple moving average for time to render screen. 0.1 factor used as smoothing
         // value.
         this.deltaTime += (Time.deltaTime - this.deltaTime) * 0.1f;
     }
 
     private AdRequest CreateAdRequest()
     {
         return new AdRequest.Builder()
             .AddTestDevice(AdRequest.TestDeviceSimulator)
             .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
             .AddKeyword("game")
             .SetGender(Gender.Male)
             .SetBirthday(new DateTime(1985, 1, 1))
             .TagForChildDirectedTreatment(false)
             .AddExtra("color_bg", "9B30FF")
             .Build();
     }
 
     private void RequestBanner()
     {
         // These ad units are configured to always serve test ads.
 #if UNITY_EDITOR
         string adUnitId = "unused";
 #elif UNITY_ANDROID
         string adUnitId = "**********my banner id*******";
 #elif UNITY_IPHONE
         string adUnitId = "";
 #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.Top);
 
         // Register for ad events.
         RegisterDelegateForBanner();
 
         // Load a banner ad.
         this.bannerView.LoadAd(this.CreateAdRequest());
     }
 
     private void RequestInterstitial()
     {
         // These ad units are configured to always serve test ads.
 #if UNITY_EDITOR
         string adUnitId = "unused";
 #elif UNITY_ANDROID
         string adUnitId = "********my interstial id***********";
 #elif UNITY_IPHONE
         string adUnitId = "";
 #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.
         RegisterDelegateForInterstitial();
 
         // Load an interstitial ad.
         this.interstitial.LoadAd(this.CreateAdRequest());
     }
 
     void RegisterDelegateForBanner()
     {
         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;
     }
 
 
     void UnregisterDelegateForBanner()
     {
         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;
     }
 
 
     void RegisterDelegateForInterstitial()
     {
         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;
     }
 
     void UnregisterDelegateForInterstitial()
     {
         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;
     }
 
     public void ShowBanner()
     {
         bannerView.Show();
     }
 
 
 
     public void ShowInterstitial()
     {
         if (interstitial.IsLoaded())
         {
             interstitial.Show();
         }
         else
         {
             RequestInterstitial();
         }
     }
 
 
 
 
 
 
 
     public void HandleAdLoaded(object sender, EventArgs args)
     {
         ShowBanner();
     }
 
     public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         UnregisterDelegateForBanner();
         RequestBanner();
     }
 
     public void HandleAdOpened(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleAdOpened event received");
     }
 
     public void HandleAdClosed(object sender, EventArgs args)
     {
         UnregisterDelegateForBanner();
         RequestBanner();
     }
 
     public void HandleAdLeftApplication(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleAdLeftApplication event received");
     }
 
 
 
     //------------------------------------------------------------
 
     public void HandleInterstitialLoaded(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleInterstitialLoaded event received");
     }
 
     public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         UnregisterDelegateForInterstitial();
         RequestInterstitial();
     }
 
     public void HandleInterstitialOpened(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleInterstitialOpened event received");
     }
 
     public void HandleInterstitialClosed(object sender, EventArgs args)
     {
         UnregisterDelegateForInterstitial();
         RequestInterstitial();
     }
 
     public void HandleInterstitialLeftApplication(object sender, EventArgs args)
     {
         MonoBehaviour.print("HandleInterstitialLeftApplication event received");
     }
 
 }
 

i am using AdController.instance.ShowInterstitial(); in othere scripts all work fine in editor i get feedback in console but nothing when i build app and use on my phone........pls help going crazy from last 2 days

Comment
Add comment · Show 2
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
avatar image NoDumbQuestion · Jun 24, 2018 at 03:48 PM 0
Share

Depend on provider and region lock. Demo Ads won't show up until you publish it.

Like I am from southeast Asia when international cable got bitten by shark. There was no ads at all, except when you turn on expensive satellite provider. Some ads show up from old app. While new app build fresh from editor won't have any

avatar image NoDumbQuestion · Jun 24, 2018 at 03:49 PM 0
Share

Also, root android phone have less Ads amd most of the time, there was no ads at all. So test on normal Android

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sumitss · Jun 24, 2018 at 04:35 PM

@NoDumbQuestion as i said above i am getting ads when i try same id's on googleadsdemoscript its only when i use those id's in my script(pasted above i am not getting any ads and sometimes app hangs and freezes ....was working perfectly when i tested it before adding ads controllers

Comment
Add comment · Show 10 · Share
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
avatar image NoDumbQuestion · Jun 24, 2018 at 04:40 PM 0
Share

You mean. You use Test ID in Android. You got ads.

But use your ID, no ads show up?

avatar image sumitss NoDumbQuestion · Jun 24, 2018 at 04:59 PM 0
Share

i used same id in googleadsdemoscript i got ads i used same id in my app i am not getting ads that's why i pasted the script may be something is wrong with my script

avatar image NoDumbQuestion sumitss · Jun 24, 2018 at 05:05 PM 0
Share
 private AdRequest CreateAdRequest()
      {
          return new AdRequest.Builder()
              .AddTestDevice(AdRequest.TestDeviceSimulator)
              .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
              .Add$$anonymous$$eyword("game")
              .SetGender(Gender.$$anonymous$$ale)
              .SetBirthday(new DateTime(1985, 1, 1))
              .TagForChildDirectedTreatment(false)
              .AddExtra("color_bg", "9B30FF")
              .Build();
      }


You know that Ads fill rate based on person demographic right? You won't get any ads for target 40+ years old. You did receice ads info on phone but server ads provider didn't give you any ads to show because there was not ads appropriate based on info you give. So all request for ads got deny

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

120 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

Related Questions

All C# Shader Scripts giving CS 8025 Parsing Error. 2 Answers

How do I inherit certain varibles and functions from another script. 1 Answer

Terrain tools error, can anyone help? 0 Answers

Can't add script to anything error 1 Answer

Visual studio says no issues found even though there are errors. 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