using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using TMPro;
public class Banner : MonoBehaviour
{
public TextMeshProUGUI textad;
private string _adUnitId = "ca-app-pub-3940256099942544/6300978111";
BannerView _bannerView;
public void Start()
{
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize((InitializationStatus initStatus) =>
{
// This callback is called once the MobileAds SDK is initialized.
});
LoadAd();
}
// These ad units are configured to always serve test ads.
/// <summary>
/// Creates a 320x50 banner at top of the screen.
/// </summary>
public void LoadAd()
{
textad.text = "Creating";
_bannerView = new BannerView(_adUnitId, AdSize.Banner, AdPosition.Top);
}
public void ShowAd()
{
// create an instance of a banner view first.
if (_bannerView == null)
{
LoadAd();
textad.text = "Ad Not Available";
}
// create our request used to load the ad.
var adRequest = new AdRequest();
// send the request to load the ad.
textad.text = "loading ad";
_bannerView.LoadAd(adRequest);
}
}
No comments:
Post a Comment