Creating rewarding video ads in Unity

Esteban Ibarra
4 min readSep 3, 2021

In our shop, we have several expensive items and the player may not have collected enough gems to purchase what they need. In this case, they’ll need to buy the castle key. We can give them an option to watch an ad for 100 gems, so let’s set that up!

turn on the shopkeeper hud, and duplicate the buy button, rename it to Unity_Ad_Button and place it up top:

Great! Next, replace the text with “Click here for 100g”, and to make the box stand out, let’s change the color to green.

Finally, clear out the buttons OnClick event. We’ll attach the Unity purchase function to this soon.

Now we’re ready to enable ads! Open Window/General/Services

Afterwhich, you’ll be asked to log in, once in, you’ll be presented with a list of services:

Enable ads, this game isn’t really for kids so we’ll not tick the under 13 box. We will however enable test mode.

Under Advanced, make sure built-in ads is turned on.

Here, you’ll be asked to log in and then select a project. You’ll be taken to Unitys services, choose the game you want to monetize, in our case Dungeon Escape, it will ask you if you’re making Unity the sole ad provider, I’m going to say yes. You can then create an Ad Unit which will be of the ‘rewarded’ type, which will force the player to watch the entire ad, and after which, be rewarded something. I’ll call my Ad Unit ‘Reward 100 Gems’.

Google will then create a dedicated page for this ad.

We’re going to need to know what our game ID is, and you can find that in the main page of Ad Units:

Make a note of your game ID, we’re going to use it soon.

Great! We’re ready to make some ad revenue! Let’s make an Ad Manager! create a script called AdManager, and also an empty called Ad_Manager to attach the script to:

This will help Unity which game it’s monetizing for its analytics.

We’re going to need some help from Unitys advertisement integration page:

Let’s just copy and paste the code from Unitys reward sample code into ours:

Now let’s attach it to our button and make sure ShowRewardedVideo is the function for the button press:

And now let’s see if it works:

Excellent! Now we just need to actually give the player 100 gems. Easy enough! We already have a function to add gems so let’s use that!\

Let’s look for the part of the script where it talks about watching the ad to completion and we’ll place our code there:

We’ll create a holder for our player and we’ll look for it with the ‘Player’ tag, and then use the AddDiamonds function to add 100 and then we’ll update the UI so we see the change in the shop.

Yes! Everything is working! So if we play this on a device, the player will watch a full ad and get 100 gems for it!

--

--