Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Advertisement.Show

Suggest a change

Success!

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.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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

Parameters

placementId Optional placement identifier. If not specified, your default placement specified in the admin settings will be used.
showOptions Specify e.g. callback handler to be called when video has finished.

Description

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 RewardedPlacementId: 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 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 }

Did you find this page useful? Please give it a rating: