Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity AdMob with offset from top

Discussion in 'Unity Ads & User Acquisition' started by dralv3s, Oct 17, 2018.

  1. dralv3s

    dralv3s

    Joined:
    Sep 23, 2018
    Posts:
    2
    Hello everyone,

    Not sure if i'm on the right section, please move it if wrong.
    I've searched the forum, Google and Stack Overflow for something related to my problem but with no success, so here goes...

    I'm new to unity development, and i'm facing the following problem, i have an AD from ADMOB on the main menu screen, when i load the game scene i destroy the ad to load it again, but for some reason it doest go all the way to the top(see the picture attached), it only happens on the first load, after the player dies and reloads the screen everything works fine.


    AdWrong.png

    I've got a script called Adscript:

    Code (CSharp):
    1. void Start()
    2.     {
    3.         _isTestAD = true;
    4.         _isShowAD = true;
    5.  
    6.         _adString = "not running yet";
    7.         _adTesteString = "ca-app-pub-3940256099942544/6300978111";
    8.                  
    9.              
    10.         if (_isTestAD)
    11.         {
    12.             _adID = _adTesteString;
    13.         }
    14.         else
    15.         {
    16.             _adID = _adString;
    17.         }
    18.  
    19.         request = new AdRequest.Builder().Build();
    20.         bannerAd = new BannerView(_adID, AdSize.SmartBanner, AdPosition.Top);
    21.              
    22.     }
    23.  
    24.     private void OnDestroy()
    25.     {
    26.         UnloadBannerAd();
    27.     }
    28.  
    29.     public void LoadBannerAd()
    30.     {
    31.         bannerAd.LoadAd(request);
    32.  
    33.     }
    34.  
    35.     public void UnloadBannerAd()
    36.     {
    37.         bannerAd.Destroy();
    38.  
    39.     }
    40.  


    And i call it from the game controller on start using a coroutine with a 2 secs delay(so the ad script finishes setting its references)

    Code (CSharp):
    1.     void Start () {
    2.  
    3.  
    4.  
    5. _adScript = GetComponent<AdScript>();
    6.  
    7.  
    8.  
    9.     StartCoroutine(LoadBanner());
    10.  
    11.     }
    12.  
    13.     IEnumerator LoadBanner()
    14.     {
    15.         yield return new WaitForSeconds(2f);
    16.         _adScript.LoadBannerAd();
    17.  
    18.     }
    Has anyone here faced this problem before? how to solve it?

    PS: another doubt, should i use try catch on my codes? on the course that i followed did not cover that part, and the instructor did not use it, i see that unity already has its exception handler, so i don't wanna be redundant.