Search Unity

Admob Banner Not Working! Getting Crazy With This!

Discussion in 'Scripting' started by zerobruga, Apr 15, 2019.

  1. zerobruga

    zerobruga

    Joined:
    Mar 17, 2019
    Posts:
    4
    Hi there!

    I got a game released on the Play Store but I'm not being able to set up a banner correctly.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using GoogleMobileAds.Api;
    5.  
    6. public class GoogleMobileAdsDemoScript : MonoBehaviour
    7. {
    8.     private BannerView bannerView;
    9.  
    10.     public void Start()
    11.     {
    12. #if UNITY_ANDROID
    13.         string appId = "ca-app-pub-XXX";
    14. #elif UNITY_IPHONE
    15.             string appId = "ca-app-pub-XXX";
    16. #else
    17.             string appId = "ca-app-pub-XXX";
    18. #endif
    19.  
    20.         // Initialize the Google Mobile Ads SDK.
    21.         MobileAds.Initialize(appId);
    22.  
    23.         this.RequestBanner();
    24.     }
    25.  
    26.     private void RequestBanner()
    27.     {
    28. #if UNITY_ANDROID
    29.         string adUnitId = "ca-app-pub-XXX";
    30. #elif UNITY_IPHONE
    31.             string adUnitId = "ca-app-pub-XXX";
    32. #else
    33.             string adUnitId = "ca-app-pub-XXX";
    34. #endif
    35.  
    36.         // Create a 320x50 banner at the top of the screen.
    37.      
    38.         bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
    39.         AdRequest request = new AdRequest.Builder().Build();
    40.         bannerView.LoadAd(request);
    41.  
    42.     }
    43. }
    This is my code, is exactly the same as the Tutorial on the main website, and it's attached to the main camera. I don't see anything in the Unity Editor or Android device...
    I need help please!
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Try attaching events like described here:
    https://developers.google.com/admob/unity/banner

    See if it fails for some reason. Also, check your logcat logs, might be worth looking into errors.

    Also, this is not a support forum. You'll probably get a better advice in the android subforum section or scripting.
     
  3. zerobruga

    zerobruga

    Joined:
    Mar 17, 2019
    Posts:
    4



    I tried to implement those things but they appear so many errors... :(
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
  5. BelalGawish

    BelalGawish

    Joined:
    Sep 17, 2019
    Posts:
    5
    import using System; library and it will work.