UnityAdsのバージョンが2.xの時のサンプルスクリプト
using UnityEngine; | |
using UnityEngine.Advertisements; | |
/// <Summary> | |
/// 広告のテストを行うサンプルコードです。 | |
/// </Summary> | |
public class AdSample : MonoBehaviour | |
{ | |
string placementId = "rewardedVideo"; | |
void Start() | |
{ | |
} | |
void Update() | |
{ | |
} | |
/// <Summary> | |
/// 動画再生のテストボタンが押された時の処理です。 | |
/// </Summary> | |
public void OnClickAdButton() | |
{ | |
// 広告の準備ができている場合に再生します。 | |
if (Advertisement.IsReady(placementId)) | |
{ | |
ShowOptions options = new ShowOptions(); | |
options.resultCallback = HandleShowResult; | |
Advertisement.Show(placementId, options); | |
} | |
} | |
/// <Summary> | |
/// 動画広告の再生結果で分岐する処理です。 | |
/// </Summary> | |
void HandleShowResult(ShowResult result) | |
{ | |
if(result == ShowResult.Finished) | |
{ | |
// 広告表示が完了した時の処理です。 | |
Debug.Log("広告の再生が終わったのでユーザーにプレゼント!"); | |
} | |
else if (result == ShowResult.Skipped) | |
{ | |
// 広告表示がスキップ時の処理です。 | |
Debug.Log("キングクリムゾン!"); | |
} | |
else if (result == ShowResult.Failed) | |
{ | |
// 広告の再生に失敗した時の処理です。 | |
Debug.Log("広告の再生に失敗しました……エラーハンドリングしましょう。"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment