How to set up rewarded ads for mobile game in Unity

Let’s go over how to add Unity ads to the platformer project.

First, open the Services window and enable ads. Enable test mode to be able to test in the inspector:

Click on Dashboard:

Select the project and enable ads:

Start a fresh project and no mediation:

Click on Ad Units:

Make a note of Game ID and Ad Unit ID:

In Unity create a script called AdsManager and add it to the Managers object:

Open up the script. Add the using statement UnityEngine.Advertisments and inherit from the interface IUnityAdsListener. Add two strings, one for the game ID and another for the placement ID (ad unit ID). Also add a bool to check if ads are available and a game object for the button that will show the ads if they are available:

In the Start function initialize Unity Ads and call the function EnableRewards with InvokeRepeating which will turn on or off the button depending if the ads are available or not:

Add the functions from the interface. In OnUnityAdsReady set _areAdsAvailable to true. Inside OnUnityAdsDidFinish reward the player if video has finished. The rest of the functions can be left blank:

Add the function that will show the rewarded video when called and also add the function that will get called repeatedly to check if the ads button should be shown:

Lastly, add the button to the shop interface and set it to call the ShowRewardedVideo function:

Final result:

Good luck!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store