Display a rewarded ad with Unity Ads
Tutorial
·
intermediate
·
+10XP
·
20 mins
·
(42)
Unity Technologies

Rewarded ads are a great way to boost engagement, letting players move beyond the free-to-play tier of your game without any financial outlay.
In this tutorial, you’ll display a rewarded video ad in a Unity project and capture the result of displaying that ad.
Languages available:
1. Overview
Rewarded ads are a great way to boost engagement, letting players move beyond the free-to-play tier of your game without any financial outlay. In this tutorial, you’ll display a rewarded video ad in a Unity project and capture the result of displaying that ad.
2. Before you begin
If you’re unfamiliar with Unity Ads (or need to refresh your memory), review Get started with Unity Ads before you start this tutorial.
3. Create a script to display the ad
To create and begin the script to display a rewarded video ad:
1. If you haven’t already, create or load a project and connect it to Unity Ads. Navigate to the dashboard and find and note your project’s Game IDs.
2. In the Hierarchy, select Add (+) and then Create Empty.
3. Name the new GameObjected “RewardedAdDisplayObject”.
4. Create a new C# script called “RewardedAdDisplay” and open it in your IDE of choice.
5. On line 4, reference the Advertisements namespace:
6. On line 6, add listeners:
7. Beginning on line 8, add:
Important: On lines 8 and 9, replace XXXXXXX with your Game IDs.
8. In Start(), beginning on line 22, add:
The code above sets some specific instructions to initialize the ad based on the hardware the app is running on.
4. Overview of the available Unity Ads Listeners
The IUnityAdsInitializationListener is an interface that has methods that handle Initialization results. These methods are:
- void OnInitializationComplete();
- void OnInitializationFailed(UnityAdsInitializationError error, string message);
The IUnityAdsLoadListener is an interface that has methods that handle Load results. These methods are:
- void OnUnityAdsAdLoaded(string adUnitId);
- void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message);
The IUnityAdsShowListener is an interface that has methods that handle Show results.. These methods are:
- void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message);
- void OnUnityAdsShowStart(string adUnitId);
- void OnUnityAdsShowClick(string adUnitId);
- void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState);
Unity recommends implementing all methods in your code, even if you do not use them all.
5. Implement the listeners’ callback methods
Now you’re ready to use those methods to complete your code:
1. Starting on line 38 of your script, create the following methods:
2. Your RewardedAdDisplay script is complete. Save your changes, review the method summary below, and then return to the Unity Editor.
Key methods of UnityAds listeners
The OnInitializationFailed, OnUnityAdsFailedToLoad, OnUnityAdsShowFailure methods will pass the error message to our myAdStatus variable.
The OnUnityAdsShowComplete method will set the adCompleted variable to true so we can see the status in the Inspector when we run the Scene.
The OnUnityAdsShowStart method will set the adStarted variable to true so we can stop trying to show the ad.
The OnUnityAdsAdLoaded method will show the ad when it’s ready, as long as the ad has not already been displayed.
Review the full RewardedAdDisplay script
6. Complete implementation and test the ad
Now you're ready to complete implementation and test the ad:
1. In the Hierarchy, select the RewardedAdDisplayObject GameObject.
2. In the Inspector window, select the lock icon (upper right corner).
3. Direct your attention to the RewardedAdDisplay (Script) component.

4. Enter Play Mode. Note that the Ad Started property in the Inspector is enabled.
5. In the Game view, select Close in the upper-right of the ad display. Note that the Ad Completed property in the Inspector is now also enabled.
Note: If there is an error, it will be displayed in the text box My Ad Status field.
6. Exit Play Mode.
7. Next steps
You have now completed setting up Unity Rewarded Ads and can successfully display the rewarded ad. In your app, you will need to verify that AdCompleted is true and, if so, reward the player.