Version: 2017.1
public static void Show ();
public static void Show (Advertisements.ShowOptions showOptions);
public static void Show (string placementId);
public static void Show (string placementId, Advertisements.ShowOptions showOptions);

参数

placementId 可选广告位标识符。如果未指定,将使用您在管理设置中指定的默认广告位。
showOptions 例如,指定视频完成时要调用的回调处理程序。

描述

在您的项目中展示广告。

另请参阅:IsReady

using UnityEngine;
#if UNITY_ADS
using UnityEngine.Advertisements; // only compile Ads code on supported platforms
#endif

public class UnityAdsExample : MonoBehaviour { public void ShowDefaultAd() { #if UNITY_ADS if (!Advertisement.IsReady()) { Debug.Log("Ads not ready for default placement"); return; }

Advertisement.Show(); #endif }

public void ShowRewardedAd() { const string RewardedPlacementId = "rewardedVideo";

#if UNITY_ADS if (!Advertisement.IsReady(RewardedPlacementId)) { Debug.Log(string.Format("Ads not ready for placement '{0}'", RewardedPlacementId)); return; }

var options = new ShowOptions { resultCallback = HandleShowResult }; Advertisement.Show(RewardedPlacementId, options); #endif }

#if UNITY_ADS private void HandleShowResult(ShowResult result) { switch (result) { case ShowResult.Finished: Debug.Log("The ad was successfully shown."); // // YOUR CODE TO REWARD THE GAMER // Give coins etc. break; case ShowResult.Skipped: Debug.Log("The ad was skipped before reaching the end."); break; case ShowResult.Failed: Debug.LogError("The ad failed to be shown."); break; } }

#endif }