Unity - Admob hide banner doesn't work

后端 未结 1 1319
野的像风
野的像风 2020-12-21 19:15

Why doesn\'t my admob banner hide when I go the next scene called \'\'Main\'\'? I did everything what other people said on other threads..

This is my code:



        
相关标签:
1条回答
  • 2020-12-21 19:53

    The problem is in the RequestBanner function:

    BannerView bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
    

    The bannerView is a local variable and the new BannerView instance will be stored to that local bannerView variable instead of the global bannerView variable.

    You need that BannerView instance to be stored in the global bannerView variable.

    That should be changed to:

    bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
    

    Another problem is here:

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

    You are destroying bannerView before hiding it. It should be the other way around. You should Hide then Destroy the bannerView. If fact, simply Hiding the bannerView should be fine. You don't have to Destroy it.

    0 讨论(0)
提交回复
热议问题