Unity 如果使用 Google Admob (Android 版)

1. 首先當然 你需要 Admob 帳號  請參考這篇 http://imax-live.blogspot.tw/2012/11/admod-account-payment-paypal.html

2.申請完後,請先下載

Google Mobile Ads Unity Plugin


3.打開Unity -> Assert -> import Package -> Custom Package 
4.匯入剛下載的GoogleMobileAds.unitypackage

5.匯入成功後,會看到專案下多了Plugin 資料夾
6.去自己的 Andorid SDK 資料夾 (沒有的話記得先去下載   ) ,找到 Google Play Lib : [sdk]\extras\google\google_play_services\libproject\google-play-services_lib

7. 複製到 Unity Assert/Plugin 目錄下

8.在Unity 建立一個 場景(Sence)

9.建立一個按鈕的 , 並且有監聽事件的C# 的 Script


10. 在監聽事件中 貼上以下 code
using GoogleMobileAds.Api;

private void RequestBanner()
{
    #if UNITY_ANDROID
        string adUnitId = "INSERT_ANDROID_BANNER_AD_UNIT_ID_HERE";
    #elif UNITY_IPHONE
        string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the banner with the request.
    bannerView.LoadAd(request);
}
11.打開Admob 控制網頁 並且登入 http://www.google.cn/ads/admob/index.html

12.點擊獲->新應用獲利


13. 建立一個 "Android" 的應用

14. 建立一個橫幅廣告

15. 複製廣告ID

16.在剛才的code 中 :

 string adUnitId = "INSERT_ANDROID_BANNER_AD_UNIT_ID_HERE";

替換成你的 廣告ID

17 . 輸出至Android (一定要Android ,用Unity 看不到效果)


18. 點擊場景上的按鈕,就可以看到效果了

Reference :https://github.com/googleads/googleads-mobile-plugins/releases
https://developers.google.com/admob/games#unity
https://github.com/googleads/googleads-mobile-plugins/tree/master/unity 


留言

這個網誌中的熱門文章

angular 如何Http 如何設定 CORS (Cross-Origin Resource Sharing)

Google Map 單車路徑計算坡度和角度小工具

Google URL Shortener API 快速教學