Created
June 26, 2020 04:50
-
-
Save todorok1/f570b2475c5cf5cdcefee705f1367652 to your computer and use it in GitHub Desktop.
UnityAdsのバージョンが2.xの時のサンプルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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