Unity Ads 導入メモ
やったこと
- Unity Ads のサイトにアカウント登録
- Unity Ads でアプリの登録とID取得
- Asset Store から Unity Ads のインポート
- 広告の呼び出しスクリプトの作成と実行
参考サイト
スクリプト例
AdsManager
using UnityEngine; using System.Collections; using UnityEngine.Advertisements; public class AdsManager : MonoBehaviour { void Awake() { if (Advertisement.isSupported) { Advertisement.allowPrecache = true; Advertisement.Initialize (Config.unityAdsId, true); } else { Debug.Log("Platform not supported"); } } public void Show() { Advertisement.Show(null, new ShowOptions { pause = true, resultCallback = result => { Debug.Log("広告閲覧終了。広告閲覧報酬を付与するならここで。"); Debug.Log(result.ToString()); } }); } }
Config
using UnityEngine; using System.Collections; public class Config { #if UNITY_IPHONE public static string unityAdsId = "iOSアプリのID"; #elif UNITY_ANDROID public static string unityAdsId = "AndroidアプリのID"; #endif }
広告表示
GameObject.FindObjectOfType<AdsManager>().Show();