Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
ClosezoneId | Optional zone identifier. If not specified, your default zone specified in the admin settings will be used. |
options | Specify e.g. callback handler to be called when video has finished. |
Show an advertisement in your project.
See Also: IsReady.
#pragma strict using UnityEngine.Advertisements; // only compile Ads code on supported platforms public class UnityAdsExample extends MonoBehaviour { public function ShowDefaultAd() { } public function ShowRewardedAd() { const var RewardedZoneId: String = "rewardedVideo"; } }
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 zone"); return; }
Advertisement.Show(); #endif }
public void ShowRewardedAd() { const string RewardedZoneId = "rewardedVideo";
#if UNITY_ADS if (!Advertisement.IsReady(RewardedZoneId)) { Debug.Log(string.Format("Ads not ready for zone '{0}'", RewardedZoneId)); return; }
var options = new ShowOptions { resultCallback = HandleShowResult }; Advertisement.Show(RewardedZoneId, 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 }