如何加载AdMob的广告到一个统一的5项目? [英] How to load admob ads into a unity 5 project?

查看:163
本文介绍了如何加载AdMob的广告到一个统一的5项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我试图加载一个横幅广告到我的团结5项目,并出口到iOS。

Basically I'm trying to load a banner ad into my Unity 5 project and export to iOS.

下面是code我打电话统一其内部连接到一个游戏对象:

Here is the code i'm calling inside of unity which is attached to a game object:

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

public class AdController : MonoBehaviour {

    InterstitialAd interstitial;
    BannerView bannerView;

    void Start () {

        //------ Banner Ad -------
        // Create a 320x50 banner at the top of the screen.
        // Put your Admob banner ad id here
        bannerView = new BannerView(
            "ca-app-pub-xxxxxxxxxxxxxxxx", AdSize.SmartBanner, AdPosition.Top);
        // Create ad request
        AdRequest request = new AdRequest.Builder().Build();
        // Load the banner with the request.
        bannerView.LoadAd(request);        
        bannerView.Show();

        //---- Interstitial Ad -----
        // Initialize an InterstitialAd.
        // Put your admob interstitial ad id here:
        interstitial = new InterstitialAd("ca-app-pub-xxxxxxxxxxxxxxx");

        //Add callback for when ad is loaded
        interstitial.AdLoaded += HandleAdLoaded;

        // Create an ad request.
        AdRequest requestInterstitial = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        interstitial.LoadAd(requestInterstitial);
    }



    public void HandleAdLoaded(object sender, EventArgs args) {

        interstitial.Show ();
    }


    void OnDestroy(){
        if (interstitial!=null) {
            interstitial.AdLoaded -= HandleAdLoaded;
            interstitial.Destroy ();
        }
        if(bannerView!=null){
            bannerView.Destroy ();
        }
    }

}

我使用的是:

I'm using:

  • 统一5.0.1f1
  • X code 6.3
  • 在谷歌统一插件2.2.1
  • 在谷歌广告SDK 7.2.1

有没有人有此投放广告?注:我没有用正确的广告单元ID替换为XXXXX

Has anyone got this to serve ads? Note: I did replace the xxxxx with the correct Ad Unit ID.

推荐答案

有一个从谷歌GitHub上的官方样本项目:

There is an official sample project from Google on GitHub:

团结例

这篇关于如何加载AdMob的广告到一个统一的5项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆