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 John Sartain · Mar 04, 2014 at 01:41 AM · save scene

Admob ads work but are on all scenes

I got a i guess ad package? from here: https://github.com/googleads/googleads-mobile-plugins/tree/master/unity/android . It worked got ads displaying and making money on Admob. The problem is that ads are displaying on all scenes (which I don't want) even though I only put the AdBanner.prefab in the scene Main. So is there a hid script or something I need to add? I'm kinda a noob so its probably a easy fix. If you want you can download the beta version of my game here: https://play.google.com/store/apps/details?id=com.joh.brickde . The screen shots are old so don't believe them.

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 golemsmk · Mar 04, 2014 at 09:51 AM 0
Share

Hello, I have no idea about your problem, so sorry. But I am having some problem with showing admob's ad. It doesn't show anything at all, and I don't know if I did something wrong. So I am very happy if you can spend a little time to help me. Thank you for reading. :)

avatar image Dblfstr · Mar 19, 2014 at 08:06 PM 0
Share

You have opened the same question here: http://answers.unity3d.com/questions/667599/admob-ads-display-on-all-scenes.html

Please close or delete this one.

avatar image bikada · May 17, 2014 at 05:57 AM 0
Share

hey, im facing same issue, did you fix it? thanks

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by cboxgo · Dec 10, 2014 at 09:14 PM

Once you setup the plugin you should be able to use one of these two methods:

Method 1 - Add this to GoogleMobileAdsDemoScript and put GoogleMobileAdsDemoScript only on levels you want ads to appear on:

 void Update()     {         
     //Destroy when leaving the level
     if (Input.GetKeyDown(KeyCode.Escape)) {
         bannerView.Hide (); 
         bannerView.Destroy();
     }
 }

Method 2 - Modify GoogleMobileAdsDemoScript with this minor change:

public static BannerView bannerView;

Then add this to your levels to control hiding and showing ads:

 void OnGUI()     {         
 
     try {    
         GoogleMobileAdsDemoScript.bannerView.Hide (); //if you want to hide it
         
         //or 
     
         GoogleMobileAdsDemoScript.bannerView.Show (); //if you want to show it     
     }
     catch(Exception e) {
         Debug.Log(e.ToString());
     }
     
 }

The GoogleMobileAdsDemoScript would only be attached to the main scene in Method 2 as it would only be loaded at the beginning and would not be destroyed at any time.

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
-1

Answer by John Sartain · Mar 12, 2014 at 04:53 AM

what would i change here using UnityEngine; using System.Runtime.InteropServices;

public class AdMobManager : MonoBehaviour { public enum Position { TOP, BOTTOM, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }

 private static AdMobManager mInstance = null;

 [SerializeField]
 private string iPhoneAdmobID;
 [SerializeField]
 private string iPadAdmobID;
 [SerializeField]
 private string androidAdmobID;
 [SerializeField]
 private Position position;
 [SerializeField]
 private string[] iosTestDeviceIDs;
 [SerializeField]
 private string[] androidTestDeviceIDs;


if UNITY_IPHONE

[DllImport("__Internal")] private static extern void installAdMobIOS_(string admobID, Position position); [DllImport("__Internal")] private static extern void addTestDeviceIDIOS_(string testDeviceID); [DllImport("__Internal")] private static extern void hideAdIOS_(); [DllImport("__Internal")] private static extern void showAdIOS_(); [DllImport("__Internal")] private static extern void refreshAdIOS_(); [DllImport("__Internal")] private static extern void releaseAdMobIOS_(); [DllImport("__Internal")] private static extern bool isIpadAdMob_(); #elif UNITY_ANDROID private AndroidJavaObject adViewController = null; #endif

 public static AdMobManager instance
 {
     get
     {
         return mInstance;
     }
 }

 public void Awake()
 {
     if (mInstance == null)
     {
         mInstance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }

 public void OnDestroy()
 {
     if (Application.isEditor) return;

if UNITY_IPHONE

    if (mInstance == this)
     {
         releaseAdMobIOS_();
     }

endif

}

 public void Start()
 {
     if (Application.isEditor) return;

     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {

         bool ipad = false;

if UNITY_IPHONE

        ipad = isIpadAdMob_();

endif

        if (ipad && iPadAdmobID != "")
         {
             install(iPadAdmobID, position);
         }
         else
         {
             install(iPhoneAdmobID, position);
         }

     }
     else if (Application.platform == RuntimePlatform.Android)
     {
         install(androidAdmobID, position);
     }
 }

 public void OnApplicationPause(bool pause)
 {
     if (Application.isEditor) return;
     if (pause)
     {

if UNITY_ANDROID

        adViewController.Call("cancelRefreshTimer");

endif

    }
     else
     {
         refresh();
     }
 }

 private void install(string admobID, Position position)
 {

if UNITY_IPHONE

    installAdMobIOS_(admobID, position);
     foreach (string device_id in iosTestDeviceIDs)
     {
         addTestDeviceIDIOS_(device_id);
     }
     refreshAdIOS_();

elif UNITY_ANDROID

    adViewController = new AndroidJavaObject("net.mikinya.admob.AdViewController");
     foreach (string device_id in androidTestDeviceIDs)
     {
         adViewController.Call("addTestDevice", device_id);
     }
     adViewController.Call("installAdMobForAndroid", admobID, (int)position);
     adViewController.Call("refreshAd");

endif

}

 public void refresh()
 {

if UNITY_IPHONE

    refreshAdIOS_();

elif UNITY_ANDROID

    adViewController.Call("refreshAd");

endif

}

 public void hide()
 {

if UNITY_IPHONE

    hideAdIOS_();

elif UNITY_ANDROID

    adViewController.Call("hideAd");

endif

}

 public void show()
 {

if UNITY_IPHONE

    showAdIOS_();

elif UNITY_ANDROID

    adViewController.Call("showAd");

endif

} }

Comment
Add comment · Show 5 · 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 Sildaekar · Mar 12, 2014 at 04:57 AM 0
Share

Just remove the line DontDestroyOnLoad(gameObject); Also don't post answers as comments. There is a comment option for a reason.

avatar image John Sartain · Mar 13, 2014 at 02:26 AM 0
Share

Thanks man for all help btw I hate to do this to you but its a diffrent script using UnityEngine; using System.Collections;

public class AdBannerObserver : $$anonymous$$onoBehaviour { private static AdBannerObserver sInstance;

 public static void Initialize() {
     Initialize(null, null, 0.0f);
 }
 
 public static void Initialize(string publisherId, string testDeviceId, float refresh) {
     if (sInstance == null) {
         // $$anonymous$$ake a game object for observing.
         GameObject go = new GameObject("_AdBannerObserver");
         go.hideFlags = HideFlags.HideAndDontSave;
         DontDestroyOnLoad(go);
         // Add and initialize this component.
         sInstance = go.AddComponent<AdBannerObserver>();
         sInstance.mAd$$anonymous$$obPublisherId = publisherId;
         sInstance.mAd$$anonymous$$obTestDeviceId = testDeviceId;
         sInstance.mRefreshTime = refresh;
     }
 }
 
 public string mAd$$anonymous$$obPublisherId;
 public string mAd$$anonymous$$obTestDeviceId;
 public float mRefreshTime;
 
 IEnumerator Start () {

if UNITY_IPHONE

    ADBannerView banner = new ADBannerView();
     banner.autoSize = true;
     banner.autoPosition = ADPosition.Bottom;
     
     while (true) {
         if (banner.error != null) {
             Debug.Log("Error: " + banner.error.description);
             break;
         } else if (banner.loaded) {
             banner.Show();
             break;
         }
         yield return null;
     }

elif UNITY_ANDROID && !UNITY_EDITOR

    AndroidJavaClass plugin = new AndroidJavaClass("jp.radiumsoftware.unityplugin.admob.AdBannerController");
     AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
     AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
     while (true) {
         plugin.CallStatic("tryCreateBanner", activity, mAd$$anonymous$$obPublisherId, mAd$$anonymous$$obTestDeviceId);
         yield return new WaitForSeconds($$anonymous$$athf.$$anonymous$$ax(30.0f, mRefreshTime));
     }

else

    return null;

endif

} } its still displaing on all scences ive removed so much and still no luck

avatar image Sildaekar · Mar 13, 2014 at 03:56 PM 0
Share

Remove DontDestroyOnLoad(go); Just anywhere you see the DontDestroyOnLoad function...remove it.

avatar image John Sartain · Mar 14, 2014 at 02:16 AM 0
Share

I have still it displays ads im gonna go bonkers

avatar image Dblfstr · Mar 19, 2014 at 08:08 PM 1
Share

Google$$anonymous$$obileAdsPlugin.HideBannerView();

avatar image
0

Answer by Sildaekar · Mar 12, 2014 at 03:02 AM

On line 42 of Assets/Plugins/GoogleMobileAds/GoogleMobileAdsPlugin.cs remove the following line:

 DontDestroyOnLoad(this);

Now it will only display on the scenes you place the prefab in

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 Dblfstr · Mar 19, 2014 at 07:59 PM 0
Share

That is not how this works. The script will create a new activity to display the ads. Destroying the prefab that called the activity, will not destroy the activity itself. So you are going to have ads once they are initialized until the game is exited.

avatar image
0

Answer by ginesinho · Mar 18, 2015 at 02:58 PM

Make public the Destroy method of the script of the Admob banner and add the next code:

 public void Destroy(){
     bannerView.Hide();
     bannerView.Destroy();
 }
 

After that, call this method when you want to hide the banner:

 bannerScript = adMobBunner.GetComponent<AdMobBunnerScript>();
 bannerScript.Destroy();
 

I tried to use only the Hide method inside the Destroy method but it works slower. It's better to put both of them.

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

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

26 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

Related Questions

Unity will not allow me to export anything, or save any new scenes 1 Answer

Passing Data Through Scenes? 1 Answer

UnitySerializer Delete Saved Games 0 Answers

Creating Scene Chunk in 2d game and Altering Prefab 0 Answers

how to accumulate game objects from the game (runtime) into the current scene? 2 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