- Home /
Admob ads display on all scenes
Im using this javascript in a prefab ads work but display in all scenes which is annoying i only want it on the menu and credits. btw i xed my publisher id sorry if the codes appears funny idk why it does that
pragma strict
var publisherId : String = "xxxxxxxxxxxxxxx"; var refreshRate : float = 60.0; var testDevice : String = "test_device_code_here"; function Start () { AdBannerObserver.Initialize(publisherId, testDevice, refreshRate); }
Format code by highlighting all your code and clicking the little box that looks like a bunch of 1's and 0's.
#pragma strict
var publisherId : String = "xxxxxxxxxxxxxxx";
var refreshRate : float = 60.0;
var testDevice : String = "test_device_code_here";
function Start () {
AdBannerObserver.Initialize(publisherId, testDevice, refreshRate);
}
Also, is this the same question?
http://answers.unity3d.com/questions/654910/admob-ads-work-but-are-on-all-scenes.html
Answer by supernat · Mar 19, 2014 at 05:41 AM
The way Unity works is with a single Activity view, and it implements a GL view to render the game scenes. It doesn't matter what scene you are showing in Unity, the same activity is used. You didn't post the rest of your code for AdMob, or maybe you're using a library, but you will need to add a couple of methods, one to Show the banners and one to Hide the banners. Like Unity, the AdMob banners will be in their own Activity that persists no matter what unity scene is showing. Your Show method should start the AdMob activity while your Hide method should stop or simply hide the AdMob activity.
Unfortunately I can't. We're talking about a significant amount of code and completely dependent on what you are using now. There's no simple "drop in" script fragment for this.
Sorry I'm a noob but would it be something like Function show(){ If scene == blah; Admob.hide; } As far as I know this is all the code attached to prefab ya there's manifest and the .j files
It's not that simple. Whatever you are using to access admob ads, surely relies on some sort of library which contain the actual admob code. Your prefab and script will simply call that one method in the admob class (create an ad). There would need to be a show and/or hide method in that admob class in order for you to call it for your ads.
Is this a free plugin, did you write it following one of the many tutorials on the subject? Is this for android.
There is a great plugin that has all the functionality you desire called android native plugin. It is $30.00, but WELL worth it. I have used it in my android games, if your game is decent you will make you money back in a week at the most.
Here is a link: https://www.assetstore.unity3d.com/#/content/10825
Saw you old question (same question). There seems to be the method for hiding ads.
https://github.com/googleads/googleads-mobile-plugins/tree/master/unity/android
Google$$anonymous$$obileAdsPlugin.HideBannerView();