如何将admob广告加载到unity 5项目中?

Edw*_*ard 5 c# unity-game-engine admob ios

基本上我正在尝试将横幅广告加载到我的Unity 5项目中并导出到iOS.

这是我在Unity中调用的代码,它附加到游戏对象:

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 ();
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

我正在使用:

  • Unity 5.0.1f1
  • Xcode 6.3
  • Google Unity插件2.2.1
  • Google Ads SDK 7.2.1

有没有人有这个广告?注意:我确实用正确的广告单元ID替换了xxxxx.

小智 1

GitHub上有一个项目:

Unity Admob 插件

它很容易使用,我在这方面取得了成功。

using admob;
...
Admob.Instance().initAdmob("admob banner id", "admob interstitial id");//admob id with format ca-app-pub-2796046890663330/756767388
Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
Run Code Online (Sandbox Code Playgroud)