Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created June 26, 2020 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/f570b2475c5cf5cdcefee705f1367652 to your computer and use it in GitHub Desktop.
Save todorok1/f570b2475c5cf5cdcefee705f1367652 to your computer and use it in GitHub Desktop.
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