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 /
  • Help Room /
avatar image
0
Question by NovaromaDesign · Nov 25, 2016 at 08:45 AM · android buildadmob

Admob Interstitial not showing

Hi, this code is probably wrong somewhere. No experience in C#... I' using Admob official plugin, but it doesn't work. I just want to show an interstital ad on load.... Thanks for any help!


public class GoogleMobileAdsDemoScript : MonoBehaviour {

private InterstitialAd interstitial;

 private void RequestInterstitial()
 {
     
     #if UNITY_ANDROID
     string adUnitId = "ca-app-pub-xxxx/xxxx";
     #elif UNITY_IPHONE
     string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
     #else
     string adUnitId = "unexpected_platform";
     #endif

        // Returns an ad request
 private AdRequest CreateAdRequest()
        {
     return new AdRequest.Builder().Build();
        }
     // Create an interstitial.
     this.interstitial = new InterstitialAd(adUnitId);

     // Load an interstitial ad.
     this.interstitial.LoadAd(this.CreateAdRequest());
     }

     private void ShowInterstitial() { 
     if (interstitial.IsLoaded()) { 
     interstitial.Show(); 
     }}

     public void Start()
     {
     ShowInterstitial();
     }

     }



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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheRealMarco · Feb 25, 2017 at 07:16 PM

You need to enter here a proper id : string adUnitId = "ca-app-pub-xxxx/xxxx";

Like : string adUnitId = "ca-app-pub-3940256099942544/1033173712";

Which is a test id provided by Unity.

You also need to call RequestInterstiticial method before the ShowInterstitial method.

And you need to put CreateAdRequest() out of RequestInterstitial().

You need to call ShowInterstitial one time, when the ad is loaded. In this example, I call it 30 times per second, which is forbidden, but it's an exemple.

 public class GoogleMobileAdsDemoScript : MonoBehaviour
 {
     private InterstitialAd interstitial;
 
     private void RequestInterstitial()
     {
         #if UNITY_ANDROID
             string adUnitId = "ca-app-pub-3940256099942544/1033173712";
         #elif UNITY_IPHONE
             string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
         #else
             string adUnitId = "unexpected_platform";
         #endif
                 
         // Create an interstitial.
         this.interstitial = new InterstitialAd(adUnitId);
         // Load an interstitial ad.
         this.interstitial.LoadAd(this.CreateAdRequest());
     }
     
     // Returns an ad request
     private AdRequest CreateAdRequest()
     {
         return new AdRequest.Builder().Build();
     }
     
     private void ShowInterstitial()
     { 
         if (interstitial.IsLoaded())
         {
             interstitial.Show(); 
         }
     }
     
     public void Start()
     {
         RequestInterstitial();
     }
     
     void Update()
     {
         ShowInterstitial();
     }
 }
Comment
Add comment · 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
0

Answer by dyenaldinesh · Dec 17, 2017 at 07:11 AM

@TheRealMarco thank u so much..it really worked...everybody use this code..

Comment
Add comment · Show 1 · 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 johnny2014 · Dec 06, 2018 at 08:53 AM 0
Share

I know this is quite an old thread, but I too am having issues with interstitials not loading.

I used the script above and it works by calling the ShowInterstitial() in the Update method, but I can't get it to work by calling it anywhere else.

Obviously we can't use it in the Update method, so does anyone have a way around it?

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

82 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

Related Questions

Build Failure with AdMob 0 Answers

Game doesn't work after adding AdMob 0 Answers

Google Mobile Ads cause Failed to build apk error 0 Answers

Gradle failed to fetch dependencies? 1 Answer

Android - Google Admob and Easy Mobile brakes build process 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