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 Charlemagne · Mar 06, 2015 at 11:55 AM · scenestaticgoogle playgoogle play gamesgoogle

Google Ads BannerView persists across scenes

I have this issue where the ad banner gets destroyed when you leave the menu scene, but if you leave the scene before the ad is actually fetched, it will show up in the game scene. Now there is no reference to it, and there is no code to destroy it. There is also no way to even check the status of an ad as far as I can tell, so the only solution I have been able to come up with is keeping a static reference to the banner, and calling destroy on it every update cycle in the game scene. This seems bad, but I can't really think of a better way of doing it. Any ideas?

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
2

Answer by Neamtzu · Mar 06, 2015 at 04:35 PM

If you're using the AdMob plugin from Prime31 you should do something like this

 public class AdsController : MonoBehaviour {
     public static AdsController Instance;
 
     void Awake() {
         if (Instance == null) {
             Instance = this;
             DontDestroyOnLoad (this.gameObject);
         }
         else
             Destroy (this.gameObject);
     }
 
     void OnEnable() {
         AdMobAndroidManager.receivedAdEvent += receivedAdEvent;
     }
 
     void OnDisable() {
         AdMobAndroidManager.receivedAdEvent -= receivedAdEvent;
     }
 
     public void showAd() {
         AdMobAndroid.createBanner( "test", AdMobAndroidAd.smartBanner, AdMobAdPlacement.BottomCenter );
     }
 
     public void destroyAd() {
         AdMobAndroid.destroyBanner();
     }
 
     void receivedAdEvent() {
         if (Application.loadedLevelName == "Game_Scene")
             destroyAd ();
     }
 }

You should add this script on a gameobject on your first scene. At runtime only 1 instance of the this class will be available in every scene of your project. In your case, the add will be called in your menu scene, if the game scene will be loaded before the ad was showed, in the game scene this script will catch the received ad event, will check if it is game scene and if so it will destroy the banner.

Use this if you want to diplay an ad

 AdsController.Instance.showAd();

If you're using another plugin, you should change "AdMobAndroidManager.receivedAdEvent" with the correspondent received ad event from your plugin.

I hope this helps.

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 Charlemagne · Mar 11, 2015 at 01:01 AM 0
Share

I am using the official plugin: https://github.com/googleads/googleads-mobile-plugins/releases/tag/v2.1

I see based on your code that I should be using the event callbacks to destroy the ad rather than try to manually check if it is loaded, and this plugin has similar functions so I should be able to implement the callbacks in the same way.

If you look here you can see the callbacks they provide: https://github.com/googleads/googleads-mobile-plugins/blob/master/unity/source/Assets/Google$$anonymous$$obileAds/Api/BannerView.cs#L10

avatar image Neamtzu · Mar 11, 2015 at 11:51 AM 0
Share

Yes, check when the "AdOpened" is triggered if you're in game scene. If so, destroy the banner.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I get email id of the google user while using playgameservices sdk? 1 Answer

Should I turn ads test mode overriding during the period of reviewing my game by the play store team? 0 Answers

Data of Google player Game service ? 0 Answers

How to remove 'com.xiaomi.account.openauth.AuthorizeActivityBase.onCreate' from my game 1 Answer

Issue with Google Play Games and PlayGamesPlatform 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