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 UniluckStudios · Sep 07, 2017 at 02:00 AM · androidiosadsadmob

Unity Admob Implementing Interstitial

In my game I want to show interstitials when someone loses. I had banner ads working great, but then I changed my code to adjust for interstitials, and now it takes a while for my banner ad to show up, and when it does it lags for a second. I also am having trouble figuring out how to get my interstitials to pop up and then request another one. I have an ad manager and the way I am telling my game when to display an ad is when the death screen pops up, then an ad should be displayed, and when the death screen goes away, I want to request another ad. So far, I haven't been able to get it to work. Here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds.Api;

 public class AdManager : MonoBehaviour {
 
     //public bool dead;
     public int showAd;
     public InterstitialAd interstitial;
     public BannerView bannerView;
 
     void Start () {
         RequestBanner ();
         showAd = Random.Range (1, 3);
         RequestInterstitial ();
     }
 
     void Awake () {
         DontDestroyOnLoad (this);
     }
 
     void Update () {
     }
 
     void ShowInterstitial () {
         if (GameObject.Find ("Canvas1").GetComponent <Canvas>().enabled) {
             if (showAd == 1) {
                 if (interstitial.IsLoaded ()) {
                     interstitial.Show ();
                     interstitial.Destroy ();
                 }
             }
         }
         if (!GameObject.Find ("Canvas1").GetComponent <Canvas> ().enabled) {
             RequestInterstitial ();
         }
     }
 
     public void RequestInterstitial()
     {
         #if UNITY_EDITOR 
         string adUnitId = "unused";
         #elif UNITY_ANDROID
         string adUnitId = "xxxxxxxxxxxx";
         #elif UNITY_IPHONE
         string adUnitId = "xxxxxxxxxxxx";
         #else
         string adUnitId = "unexpected_platform";
         #endif
 
         // Initialize an InterstitialAd.
         interstitial = new InterstitialAd(adUnitId);
         // Create an empty ad request.
         AdRequest request = new AdRequest.Builder()
         .AddTestDevice ("xxxxxxxxxxxx")
         .Build();
         // Load the interstitial with the request.
         interstitial.LoadAd(request);
         }
 
 
     void RequestBanner()
     {
         #if UNITY_EDITOR
         string adUnitId = "unused";
         #elif UNITY_ANDROID
         string adUnitId = "xxxxxxxxxxxxx";
         #elif UNITY_IPHONE
         string adUnitId = "xxxxxxxxxxxxx";
         #else
         string adUnitId = "unexpected_platform";
         #endif
 
         // 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()   
         //.AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
         .AddTestDevice("xxxxxxxxxxx")  // My test device.
         .Build();
 
         // Load the banner with the request.
         bannerView.LoadAd(request);
     }
 
 
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by horatiu2004 · Sep 08, 2017 at 09:59 AM

Hello @UniluckStudios, what version of Unity are you using? As you can see the ADBannerView functionality is deprecated in Unity 2017, so be careful.

Regarding interstitial Ads, you should be "using UnityEngine.Advertisements;". Here is an example from Unity's User Manual:

 using UnityEngine;
 #if UNITY_ADS
 using UnityEngine.Advertisements;
 #endif
 
 public class UnityAdsExample : MonoBehaviour
 {
     public void ShowDefaultAd()
     {
 #if UNITY_ADS
         if (Advertisement.IsReady())
         {
             Advertisement.Show();
         }
 #endif
     }
 }

To give a reward, you can just pass your result callback from your advertisement like this:

 const string RewardedPlacementId = "rewardedVideo";        
 var options = new ShowOptions { resultCallback = HandleShowResult };
 Advertisement.Show(RewardedPlacementId, options);

From here just implement what you require in the HandleShowResult() method.

 private void HandleShowResult(ShowResult result)
 {
   //Can use result to check if an add has  Finished, Skipped or Failed       
   DoStuff();
 }

Don't forget to Enable Ads from Services. To learn more see Unity's pages on the subject.

Comment
Add comment · Show 2 · 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 UniluckStudios · Sep 08, 2017 at 07:52 PM 0
Share

I am using Ad$$anonymous$$ob, not unity ads

avatar image UniluckStudios · Sep 08, 2017 at 07:52 PM 0
Share

Thank you for the help though

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

161 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 Memory Issues 0 Answers

Interstitial pause game on Android but not on iOS? 5 Answers

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

Admob interstitial ad are slowing my game down 0 Answers

How to enable ads in your games. 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