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 auhan · Nov 28, 2015 at 02:41 PM · admob

Why cannot I show Interstitial ads?

Hello everyone,

I have tried many things but I could not make interstitial ads display. I want to show interstitial ads after users select a wrong answer and before the score page ("Notice" scene) displays. Here is my code, I just copied relevant parts:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Text;
 using System.Xml;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Xml.Serialization;
 using System.IO;
 using GoogleMobileAds;
 using GoogleMobileAds.Api;
 
 public class responder : MonoBehaviour
 {
     private InterstitialAd interstitial;
 
     private int gecis;
 
     public Text questionsorular;
     public Text responseA;
     public Text responseB;
     public Text responseC;
     public Text responseD;
     public Text infoResponses;
     public Text infoResponses1;
     public Text example;
     public Text dogrusayisi;
 
     private float corrects;
     private float questoesquestions;
     private float media;
     private int Notice;
 }
 
 void Start()
 {
     RequestInterstitial();
 }
 
 public void response(string alternative)
 {
 
     RequestInterstitial();
 
     if (alternative == "A")
     {
         if (responseA.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }
 
     else if (alternative == "B")
     {
         if (responseB.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }
 
     else if (alternative == "C")
     {
         if (responseC.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }
 
     else if (alternative == "D")
     {
         if (responseD.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }
 }
 
 void wrong()
 {
     ShowInterstitial();
     Application.LoadLevel("Notice");
 }
 
 private void RequestInterstitial()
 {
 #if UNITY_EDITOR
     string adUnitId = "unused";
 #elif UNITY_ANDROID
             string adUnitId = "MY ADS ID";
 #elif UNITY_IPHONE
             string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
 #else
             string adUnitId = "unexpected_platform";
 #endif
 
     // Create an interstitial.
     interstitial = new InterstitialAd(adUnitId);
     // Load an interstitial ad.
     interstitial.LoadAd(createAdRequest());
 }
 
 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 ShowInterstitial()
 {
     if (interstitial.IsLoaded())
     {
         interstitial.Show();
     }
 }
 

Following code works perfectly for banner ads when I attached it to camera:

 using UnityEngine;
 using GoogleMobileAds.Api;
 
 public class Ads : MonoBehaviour
 {
     void Start()
     {
         BannerView adsObject = new BannerView(
                 "MY ADS ID", AdSize.SmartBanner, AdPosition.Bottom);
         AdRequest getAds = new AdRequest.Builder().Build();
         adsObject.LoadAd(getAds);
         }
 }
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
Best Answer

Answer by auhan · Nov 29, 2015 at 10:48 PM

I finally did it.

  using UnityEngine;
  using UnityEngine.UI;
  using System.Text;
  using System.Xml;
  using System.Collections;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Xml.Serialization;
  using System.IO;
  using GoogleMobileAds;
  using GoogleMobileAds.Api;
 
  public class responder : MonoBehaviour
  {
      private InterstitialAd adObject;
 
      private int gecis;
 
      public Text questionsorular;
      public Text responseA;
      public Text responseB;
      public Text responseC;
      public Text responseD;
      public Text infoResponses;
      public Text infoResponses1;
      public Text example;
      public Text dogrusayisi;
 
      private float corrects;
      private float questoesquestions;
      private float media;
      private int Notice;
  }
 
  void Start()
  {
      GetNewAds( null, null );
  }
 
  public void response(string alternative)
  {
 
 
      if (alternative == "A")
      {
          if (responseA.text == infoResponses.text)
          {
              corrects += 1;
              nextQuestion();
          }
          else
          {
              Invoke("wrong", 1);
          }
      }
 
      else if (alternative == "B")
      {
          if (responseB.text == infoResponses.text)
          {
              corrects += 1;
              nextQuestion();
          }
          else
          {
              Invoke("wrong", 1);
          }
      }
 
      else if (alternative == "C")
      {
          if (responseC.text == infoResponses.text)
          {
              corrects += 1;
              nextQuestion();
          }
          else
          {
              Invoke("wrong", 1);
          }
      }
 
      else if (alternative == "D")
      {
          if (responseD.text == infoResponses.text)
          {
              corrects += 1;
              nextQuestion();
          }
          else
          {
              Invoke("wrong", 1);
          }
      }
  }
 
  void wrong()
  {
      StartCoroutine(ShowAds());
      Application.LoadLevel("Notice");
  }
 
 IEnumerator ShowAds()
     {
         while( !adObject.IsLoaded() )
             yield return null;
  
         adObject.Show();
     }
  
     public void GetNewAds( object sender, EventArgs args )
     {
         if( adObject != null )
             adObject.Destroy();
          
         adObject = new InterstitialAd( "AD UNIT ID" );
         adObject.AdClosed += GetNewAds;
          
         AdRequest GetAds = new AdRequest.Builder().Build();
         adObject.LoadAd( GetAds );
     }
 }
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 Karmate · Nov 28, 2015 at 11:23 PM

 private void ShowInterstitial()
  {
      //if not loaded, do nothing!
      if (interstitial.IsLoaded())
      {
          interstitial.Show();
      }
  }

Fixed Version:

 void wrong()
  {
      StartCoroutine ("ShowAd");
      Application.LoadLevel("Notice");
  }
 
 IEnumerator ShowAd ()
 {
         //wait until loaded
         while (!interstitial.IsLoaded())
             yield return null;
 
         interstitial.Show ();
 }
Comment
Add comment · Show 3 · 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 auhan · Nov 29, 2015 at 12:07 AM 0
Share

@$$anonymous$$armate Thank you for your response but it also does not work. :( I am gonna lose my $$anonymous$$d, in console both codes work perfectly, it says Dummy IsLoaded and Dummy ShowInterstitial but they do not display in my android phone.

avatar image Karmate · Nov 29, 2015 at 10:25 AM 0
Share

Hey, this is my code and works perfect. Check it. You need to call Show() method.

I use this plugin. https://github.com/googleads/googleads-mobile-unity/releases

 using UnityEngine;
 using System.Collections;
 using Google$$anonymous$$obileAds.Api;
 
 public class Ads : $$anonymous$$onoBehaviour
 {
     string caPub = "ca-app-pub-6798468007925431/xxxxxxxxx";
 
     InterstitialAd reklamObjesi;
     
     public void Show ()
     {    
         reklamObjesi = new InterstitialAd (caPub);
         AdRequest reklamiAl = new AdRequest.Builder ().Build ();
         reklamObjesi.LoadAd (reklamiAl);
         StartCoroutine ("ReklamiGoster");
     }
     
     IEnumerator ReklamiGoster ()
     {
         while (!reklamObjesi.IsLoaded())
             yield return null;
         
         reklamObjesi.Show ();
     }
 }
avatar image auhan Karmate · Nov 29, 2015 at 10:47 PM 0
Share

Thank you my friend. You gave me a different idea and I found a new code that works like a charm!

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

32 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

Related Questions

admob plugin for ios and android 1 Answer

Is there a way to save the xcode settings after build? 4 Answers

How to add AdMob into unity game? 1 Answer

how to pop interstital once a day? 1 Answer

Admob banner is not showing 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