如何在场景变化中隐藏横幅广告Unity AdMob?

And*_*aff 2 c# unity-game-engine admob

我正在创建一个新的Unity应用程序,我想在游戏过程中在屏幕顶部运行横幅广告.但是,我不希望在任何其他场景中都有横幅广告.我已尽力尝试一切,但只有一个代码组合让我甚至可以投放广告.任何其他组合都会导致立即崩溃.我附上了我在下面使用的代码,但它只显示广告并且无法隐藏它们.

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

itc*_*hee 5

在卸载(破坏)场景时销毁BannerView:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)