简体   繁体   中英

How do you hide banner ads on scene changes Unity AdMob?

I am creating a new Unity app, and I want to have banner ads run at the top of the screen during game play. However, I don't want to have banner ads in any other scene. I have tried just about everything I can, but only one combination of code lets me even run the ads. Any other combination results in an immediate crash. I have attached the code that I am using below, but it only shows the ads and is incapable of hiding them.

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;

public class Banner : MonoBehaviour {
    void Start(){
        BannerView bannerView = new BannerView ("************", AdSize.Banner, AdPosition.Top);
        AdRequest request = new AdRequest.Builder().Build ();
        bannerView.LoadAd(request);
        bannerView.Show();
    }
}

Destroy the BannerView upon unloading (destroying) the scene:

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;

public class Banner : MonoBehaviour {
    private BannerView bannerView;

    void Start() {
        bannerView = new BannerView ("************", AdSize.Banner, AdPosition.Top);
        AdRequest request = new AdRequest.Builder().Build ();
        bannerView.LoadAd(request);
        bannerView.Show();
    }

    void OnDestroy() {
        bannerView.Destroy();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM