Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

AdMob Problem

Discussion in '2D' started by RunOrDi33, Dec 23, 2019.

Thread Status:
Not open for further replies.
  1. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    Hi everyone , i have a S*** problem in my game .. i have tested my game on my mobile before adding admob and it worked fine but when i added admob with script and trying to test on my phone , the app crashes and didn't open ...
    1- i have enabled Google AdMob from android settings like the image .
    2- i have added the same app id in google admob and manifest like in image .
    3- i have created empty object and attached the script into it .
    4- the ads works perfectly in my Console in unity like in the image .

    Please everyone i need your help ... i have tried many ways but i still have the problem .. i need your help guys
    and thanks for everyone .

    here is my code.....

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using GoogleMobileAds.Api;
    5.  
    6. public class ADMOBADS : MonoBehaviour
    7. {
    8.  
    9.     private BannerView bannerView;
    10.  
    11.     void Start()
    12.     {
    13.         // Initialize the Google Mobile Ads SDK.
    14.         MobileAds.Initialize(initStatus => { });
    15.         this.RequestBanner();
    16.     }
    17.  
    18.     private void RequestBanner()
    19.     {
    20. #if UNITY_ANDROID
    21.         string adUnitId = "ca-app-pub-3940256099942544/6300978111";
    22. #elif UNITY_IPHONE
    23.             string adUnitId = "ca-app-pub-3940256099942544/2934735716";
    24. #else
    25.             string adUnitId = "unexpected_platform";
    26. #endif
    27.  
    28.         // Create a 320x50 banner at the top of the screen.
    29.         this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
    30.  
    31.         // Create an empty ad request.
    32.         AdRequest request = new AdRequest.Builder().Build();
    33.  
    34.         // Load the banner with the request.
    35.         this.bannerView.LoadAd(request);
    36.     }
    37. }
     

    Attached Files:

  2. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    Fixed... now it works perfectly :)
     
  3. joao_unity982

    joao_unity982

    Joined:
    Oct 28, 2019
    Posts:
    4
    Hey, RunOrDi. What was your work to works fine?
     
  4. Juandapp

    Juandapp

    Joined:
    May 11, 2016
    Posts:
    53
    Thanks for helping the community with your solution. and think of other people who have the same problem. Your solution was flawless, thanks for sharing it. ............................. sarcasm ...
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,513
    This old thread isn't related to 2D at all so I've gone ahead and locked the thread.
     
Thread Status:
Not open for further replies.