Skip to content

Instantly share code, notes, and snippets.

@gclsoft
Created August 23, 2014 16:55
Show Gist options
  • Save gclsoft/cce67dc7c7208b871823 to your computer and use it in GitHub Desktop.
Save gclsoft/cce67dc7c7208b871823 to your computer and use it in GitHub Desktop.
play.cs
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using System;
public class play : MonoBehaviour {
public InterstitialAd interstitial;
public InterstitialAd interstitial2;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void loadBasicBanner()
{
AdSize adSize = new AdSize(250, 250);
// Create a 320x50 banner at the top of the screen.
BannerView bannerView = new BannerView(
"ca-app-pub-0243484158988577/4626472594", adSize, AdPosition.Bottom);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
void ShowAd()
{
if (interstitial.IsLoaded()) {
interstitial.Show();
}
}
void ShowAd2()
{
if (interstitial2.IsLoaded()) {
interstitial2.Show();
}
}
void initAd()
{
// Initialize an InterstitialAd.
interstitial = new InterstitialAd("ca-app-pub-0243484158988577/4626472594");
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
//void
public InterstitialAd CreateAndLoadInterstitial() {
// Initialize an InterstitialAd.
InterstitialAd interstitial = new InterstitialAd("ca-app-pub-0243484158988577/4626472594");
// Register for ad events.
interstitial.AdLoaded += delegate(object sender, EventArgs args) {};
// interstitial.AdFailedToLoad += delegate(object sender, AdFailToLoadEventArgs args) {};
interstitial.AdOpened += delegate(object sender, EventArgs args) {};
interstitial.AdClosing += delegate(object sender, EventArgs args) {};
interstitial.AdClosed += delegate(object sender, EventArgs args) {};
interstitial.AdLeftApplication += delegate(object sender, EventArgs args) {};
// Load the InterstitialAd with an AdRequest.
interstitial.LoadAd(new AdRequest.Builder().Build());
return interstitial;
}
void OnGUI()
{
//GUI.skin.button.wordWrap = true;
if (GUI.Button(new Rect(0, 0, 300, 100), "initAd"))
{
initAd();
}
if (GUI.Button(new Rect(0, 200, 300, 100), "initAd"))
{
ShowAd();
}
if (GUI.Button(new Rect(0, 400, 300, 100), "loadBasicBanner"))
{
loadBasicBanner();
}
if(GUI.Button(new Rect(0, 600, 300, 100), "CreateAndLoadInterstitial2"))
{
interstitial2=CreateAndLoadInterstitial();
}
if(GUI.Button(new Rect(0, 800, 300, 100), "Show CreateAndLoadInterstitial2"))
{
ShowAd2();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment