Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 EmilioDLC · Jul 17, 2014 at 09:24 AM · iosadmob

how to show ad at the end like flappy bird? iOS

Hi all,

I've done the whole mob ad deal from here (https://github.com/googleads/googleads-mobile-plugins/tree/master/unity) and I got to the point where I have my ad show up at the beginning of the game and is then hidden when the player touches on the START button on my first scene. I put the script (AdScript) with the RequestBanner, hideBanner and showBanner methods in an empty prefab with the DontDestroyOnLoad(transform.gameObject); on Awake void so it stays on through the 3 scenes of my game. I do this because apparently Google does not like it when an ad is requested more than a few times per session. I thought I could then call the showBanner method from a script in another object with a function event since this function(method) already instantiates a bunch of my game over GUI Textures and GUI Texts (with current and best score):

 Public void gameOverStuff(){
              ...
             AdScript adScript = GetComponent<AdScript>();
             adScript.showBanner();
         }

or

 public AdScript adScript;
  
 
           Public void gameOverStuff()
           {
           ...
           adScript.showBanner();
           }
         

But, neither is working. . . I am not getting any errors but I am also not getting the banner ad to show when the gameOverStuff function event is called. Yes, I added the empty with the AdScript into the adScript slot in the editor. I could try destroying and instantiating the empty prefab with my AdScript requesting the banner on awake but that just sounds so dirty.

I hope it makes sense. My head is spinning now.

Thanks!

Comment
Add comment · Show 3
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 Saad_Khawaja · Jul 17, 2014 at 09:49 AM 0
Share

Please post your AdScript.cs code here as well.

avatar image EmilioDLC · Jul 17, 2014 at 07:04 PM 0
Share

here is the Adscript:

 using System;
 using UnityEngine;
 using Google$$anonymous$$obileAds;
 using Google$$anonymous$$obileAds.Api;
 
 // Example script showing how to invoke the Google $$anonymous$$obile Ads Unity plugin.
 public class startAdsScript : $$anonymous$$onoBehaviour
 {
     
     private BannerView bannerView;
     
     void Awake()
     {
         DontDestroyOnLoad(transform.gameObject);
     }
 
     void Start()
     {
         RequestBanner();
 
     }
     
     private void RequestBanner()
     {
         #if UNITY_EDITOR
         string adUnitId = "unused";
         #elif UNITY_ANDROID
         string adUnitId = "INSERT_ANDROID_BANNER_AD_UNIT_ID_HERE";
         #elif UNITY_IPHONE
         string adUnitId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
         #else
         string adUnitId = "unexpected_platform";
         #endif
         
         // Create a 320x50 banner at the top of the screen.
         bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
         // Register for ad events.
         bannerView.AdLoaded += HandleAdLoaded;
         bannerView.AdFailedToLoad += HandleAdFailedToLoad;
         bannerView.AdOpened += HandleAdOpened;
         bannerView.AdClosing += HandleAdClosing;
         bannerView.AdClosed += HandleAdClosed;
         bannerView.AdLeftApplication += HandleAdLeftApplication;
         // Load a banner ad.
         bannerView.LoadAd(createAdRequest());
     }
 
     // Returns an ad request with custom ad targeting.
     private AdRequest createAdRequest()
     {
         return new AdRequest.Builder()
                 .AddTestDevice(AdRequest.TestDeviceSimulator)
                 .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
                 .Add$$anonymous$$eyword("kpop")
                 .SetGender(Gender.$$anonymous$$ale)
                 .SetBirthday(new DateTime(1985, 1, 1))
                 .TagForChildDirectedTreatment(false)
                 .AddExtra("color_bg", "9B30FF")
                 .Build();
         
     }
 
     public void hideBanner()
     {
         bannerView.Hide();
     }
 
     public void showBanner()
     {
         bannerView.Show();
     }
 
     
     #region Banner callback handlers
     
     public void HandleAdLoaded(object sender, EventArgs args)
     {
         print("HandleAdLoaded event received.");
     }
     
     public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         print("HandleFailedToReceiveAd event received with message: " + args.$$anonymous$$essage);
     }
     
     public void HandleAdOpened(object sender, EventArgs args)
     {
         print("HandleAdOpened event received");
     }
     
     void HandleAdClosing(object sender, EventArgs args)
     {
         print("HandleAdClosing event received");
     }
     
     public void HandleAdClosed(object sender, EventArgs args)
     {
         print("HandleAdClosed event received");
     }
     
     public void HandleAdLeftApplication(object sender, EventArgs args)
     {
         print("HandleAdLeftApplication event received");
     }
     
     #endregion
 
 }

avatar image EmilioDLC · Jul 17, 2014 at 10:04 PM 0
Share

In xcode I am getting this: Thread 1: EXC_BAD_ACCESS (code=1, address=0x0). and on this stack overflow entry apararently that means "A null pointer is returned if there are no tokens left to retrieve."

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Reeceg · Jul 18, 2014 at 02:21 AM

You could use a collider at the start that sets showbanner.enabled = true then when you exit it showbanner.enabled = false and do the same at the end

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 EmilioDLC · Aug 06, 2014 at 07:56 PM

I got it to work with the .FindWithTag. I don't know why the previous 2 ways don't work for me:

 private startAdsScript startadsScript;

 GameObject AdsEmpty = GameObject.FindWithTag ("GoogleEmptyTag");
         if (AdsEmpty != null)
         {
             startadsScript = AdsEmpty.GetComponent <startAdsScript>();
         }
         if (startadsScript == null) 
         {
             Debug.Log ("Cannot find 'startAdsScript' script");
         }
         startadsScript.showBanner(); 

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 MoliCat · Sep 29, 2014 at 03:33 PM 0
Share

do we need this code?

  {
         return new AdRequest.Builder()
                 .AddTestDevice(AdRequest.TestDeviceSimulator)
                 .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
                 .Add$$anonymous$$eyword("kpop")
                 .SetGender(Gender.$$anonymous$$ale)
                 .SetBirthday(new DateTime(1985, 1, 1))
                 .TagForChildDirectedTreatment(false)
                 .AddExtra("color_bg", "9B30FF")
                 .Build();
  
     }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

'GADAdmobExtras.h' file not found 0 Answers

Integrate Admob in iOS and windows phone 0 Answers

AdMob iOS for Unity 4.1 2 Answers

Admob interstitial suddenly disappear after showing 0 Answers

Unity iOS Build Bitcode Issue 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