Search Unity

Admob BannerAd Problem

Discussion in 'Getting Started' started by lozmac97, Jan 10, 2019.

  1. lozmac97

    lozmac97

    Joined:
    Jan 4, 2019
    Posts:
    1
    Hi, I've got my banner ad to display in my game now when it boots up, my game has two scenes, a main menu and a game scene, the banner displays when the game launches in to the main menu but I want it to only display the ad in the main menu, not in the game. can anyone help me? thanks!

    this is the banner ad request code:


    using UnityEngine;
    using System.Collections;
    using GoogleMobileAds.Api;

    public class Admob : MonoBehaviour {


    // Use this for initialization
    void Start()
    {
    //Request Ads
    RequestBanner();

    }

    private void RequestBanner()
    {
    #if UNITY_EDITOR
    string adUnitId = "unused";
    #elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-3940256099942544/6300978111";
    #elif UNITY_IPHONE
    string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
    #else
    string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the bottom of the screen.
    BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the banner with the request.
    bannerView.LoadAd(request);
    }
    }
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Welcome! Please see this thread about using code tags to format your code properly. It makes reading code on here much less horrible for the rest of us.

    So just giving your code a quick glance, I can see that you're loading the ad on Start, which presumably runs from your main menu. But I don't see any code anywhere that seems to tell the banner to go away. I would think you'd want to call that when you change scenes to your gameplay scene.
     
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    So you responded via private message, which is fine, but the whole point of the forums is to be public so that other people can find the thread and maybe resolve their own issues in the future. So I'll post my response to your message here.

    I've not used AdMob, but from looking at the documentation, you destroy a banner by calling:
    Code (CSharp):
    1. bannerView.Destroy();
    So as long as you have a reference to your AdMob MonoBehaviour from the code that changes your scenes, you can make a call from there to drop the banner.

    However...

    I want to use this opportunity to soap box a bit. And also to just get real with you.

    You mentioned this is the first game you've ever made. You also seem like you're pretty new to writing code, which suggests you're not all that far along with making your game. If that's the case, integrating ads are pretty much the last thing you should be focusing on right now (if you even do it at all...).

    Let's say you finish your game, and it's a bit of fun and simply chock full of ads. You get it published to both the App Store and Google Play, but you don't spend a fortune on advertising to promote it. In your first month, you get 500 downloads between the two platforms. Heck, let's make it a thousand. No, five thousand! Most users play the game once or twice for a few minutes and forget about it. A few months down the road, they're installing something else and see your game in the list, and decide to uninstall it.

    But you have a handful of people who play for at least five minutes, every day. After that first month, you wanna know how much money you made from those ads?

    $0.

    Ads are not a great way to make money for most games. If you have a massive user base, then okay. But you're simply not going to have that. Especially not if you're annoying all your new users with ads right out of the gate. Ads are an annoyance at best and an unforgivable obstruction at worst.

    Players will look past them when the core gameplay loop is so enjoyable that it's worth dealing with the ads, so making that amazing game loop should be your primary focus. Once you determine you have that (not just in your head... it has to exist), then you can consider adding ads. But even then, I'd say release the game first, and if gets lots of downloads, push an update adding ads if you must.

    Your first game is not going to make you a fortune. Hell, your first game won't even be profitable if you have to buy licenses or asset store packages. This is fine. You should be focusing on learning how to make games right now, and see the process through to the end. You can make your fortune later.

    If you really just want the quick cash, you will not find it in game development. It'd be faster and actually easier to get a part-time job at a local fast food restaurant, because that's at least guaranteed money.

    Do what you will. But if you want to make games, please consider my advice and focus on that instead of how to spread ad platforms around. Good luck.
     
    JeffDUnity3D likes this.