Unity Admob Banner Ads Tutorial Admob Banner Ads In Unity

Unity Admob Banner Ads Tutorial | Admob Banner Ads In Unity

Unity Admob Banner Ads Tutorial | Admob Banner Ads In Unity :- This tutorial walks you through integrating AdMob banner ads into your Unity game or app. You’ll start by creating an AdMob account and setting up your ad unit in the AdMob dashboard. The guide then covers importing the Google Mobile Ads SDK into Unity and configuring it for your project. You’ll learn how to initialize the SDK and implement banner ads, including positioning and size adjustments to fit your app’s design. By following this tutorial, you’ll be able to monetize your app with banner ads while maintaining a smooth and engaging user experience.

CONTACT US TO ADD 10 AD NETWORKS TO YOUR UNITY PROJECT – CHARGES APPLY

DOWNLOAD ADMOB PLUGIN

FULL ADMOB BANNER ADS SCRIPT

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

public class BannerAds : MonoBehaviour
{
    BannerView bannerView;
    public string bannerId = "";


    // Start is called before the first frame update
    void Start()
    {

        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
            CreateBannerView();
        });

    }

    public void CreateBannerView()
    {
        Debug.Log("Creating banner view");

        // If we already have a banner, destroy the old one.
        if (bannerView != null)
        {
            DestroyAd();
        }

        // Create a 320x50 banner at top of the screen
        bannerView = new BannerView(bannerId, AdSize.Banner, AdPosition.Bottom);
        ShowBanner();
    }

    public void ShowBanner()
    {
        // create an instance of a banner view first.
        if (bannerView == null)
        {
            CreateBannerView();
        }

        // create our request used to load the ad.
        var adRequest = new AdRequest();

        // send the request to load the ad.
        Debug.Log("Loading banner ad.");
        bannerView.LoadAd(adRequest);
    }

    private void ListenToAdEvents()
    {
        // Raised when an ad is loaded into the banner view.
        bannerView.OnBannerAdLoaded += () =>
        {
            Debug.Log("Banner view loaded an ad with response : "
                + bannerView.GetResponseInfo());
        };
        // Raised when an ad fails to load into the banner view.
        bannerView.OnBannerAdLoadFailed += (LoadAdError error) =>
        {
            Debug.LogError("Banner view failed to load an ad with error : "
                + error);
            CreateBannerView();
        };
        // Raised when the ad is estimated to have earned money.
        bannerView.OnAdPaid += (AdValue adValue) =>
        {
            Debug.Log(String.Format("Banner view paid {0} {1}.",
                adValue.Value,
                adValue.CurrencyCode));
        };
        // Raised when an impression is recorded for an ad.
        bannerView.OnAdImpressionRecorded += () =>
        {
            Debug.Log("Banner view recorded an impression.");
        };
        // Raised when a click is recorded for an ad.
        bannerView.OnAdClicked += () =>
        {
            Debug.Log("Banner view was clicked.");
        };
        // Raised when an ad opened full screen content.
        bannerView.OnAdFullScreenContentOpened += () =>
        {
            Debug.Log("Banner view full screen content opened.");
        };
        // Raised when the ad closed full screen content.
        bannerView.OnAdFullScreenContentClosed += () =>
        {
            Debug.Log("Banner view full screen content closed.");
        };
    }

    public void DestroyAd()
    {
        if (bannerView != null)
        {
            Debug.Log("Destroying banner view.");
            bannerView.Destroy();
            bannerView = null;
        }
    }
}

By completing this Unity AdMob Banner Ads tutorial, you’ve equipped yourself with the knowledge to effectively monetize your app through banner ads. You now understand how to set up AdMob, integrate the Google Mobile Ads SDK into Unity, and deploy banner ads that can generate revenue while preserving a positive user experience. Implementing these ads can help you support your app’s development and future enhancements. Keep refining your ad strategy and stay updated with best practices to optimize both revenue and user satisfaction. Happy developing!

***CHECK FULL VIDEO TUTORIAL***

Visit www.UnitySourceCode.store

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping