Unity: Simple example of integrating the Banner adv into your game (Part 3/4)

integrating the banner adv, admob adsense into your game

· 2 min read
Unity: Simple example of integrating the Banner adv into your game (Part 3/4)

For the prerequisite steps, such as how to install Unity Advertisement package and integrated into project, please have a look at this:

Unity: Integrate the Advertisement package and monetize your game (Part 1/4)
Install the Advertisement package and setup environment‌There are few things needed before integration, and first of all you need toinstall the Unity Advertisement package: Step 1: Install Unity Advertisement package:Till now, the latest version is 3.4.7, you can use newer version if you like. …

Banner ads is one of the most popular ways to show ads in most of the game. We can create a banner ads by Add placement and then add a new placement:

Now you can create an empty game object and load the banner at game starts:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

public class BannerAdManager : MonoBehaviour {

    #if UNITY_IOS
    private string gameId = "1234567";
    #elif UNITY_ANDROID
    private string gameId = "1234568";
    #endif

    public string placementId = "my_banner";
    public bool testMode = true;

    void Start () {
        Advertisement.Initialize (gameId, testMode);
        StartCoroutine (ShowBannerWhenReady ());
    }

    IEnumerator ShowBannerWhenReady () {
        while (!Advertisement.IsReady (placementId)) {
            yield return new WaitForSeconds (0.5f);
        }
        Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
        Advertisement.Banner.Show (placementId);
    }
}

What is the next from here?