How to integrate admob banner and interstitial ads in your Unity game ?

Integrate admob banner and interstitial ads in your Unity game

Integrate admob banner and interstitial ads in your Unity game

This tutorial help you to add admob interstitial and banner ads in your android unity game.

Step 1

Create your apps banner & interstitial ID’s from https://www.admob.com/

admob

Step 2

Download latest unity admob plugin from  https://github.com/googleads/googleads-mobile-unity/releases

Step 3

Open your project in unity and import the admob package into your project

import

Step 4

Add permission to use internet in your AndroidManifest.xml File by using following line of code.

<!-- Required --><uses-permissionandroid:name="android.permission.INTERNET"/>

Step 5

Now move to your c# file where you want to implement ads

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
using DG.Tweening;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using GoogleMobileAds.Api;         // add this line to import admob library

public class GameManager : MonobehaviourHelper
{
 InterstitialAd interstitial;
 public int adcount = 1;

 private void RequestBanner()
    {
        #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-39408797879842544/878797897";     // Add your banner ID here
        //#elif UNITY_IPHONE
        //                string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
        //#else
        //                string adUnitId = "unexpected_platform";
        #endif

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

private void RequestInterstitial()
    {
        #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-392245445942544/1055173325";      // Add your interstitial ID here

        #endif

        // Initialize an InterstitialAd.
        interstitial = new InterstitialAd(adUnitId);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        interstitial.LoadAd(request);



    }

    private void GameOver1()
    {
        if (interstitial.IsLoaded())      // Call this function in the event where you want to display interstitial ads
        {
            interstitial.Show();
          
        }
    }

void Start()
  {

        RequestBanner();
        RequestInterstitial();          // Add these 2 functions for requesting the ads 
        
    }

}