Unity ads, monetization with benefits to the player.

Look, I know no one likes ads, but sometimes they are a necessary evil right?

With a NPC shop I had created I set off to create a special button to have the player watch an ad and get rewarded with in game currency only if they finish the entire ad. I don’t like ads as much as the next person but hey it is something I need to learn.

With the services tab open, we can go to the ads section, enable it and head to the dashboard to get the information we need to start coding.

In the dashboard, you can see various things like revenue reports but for now what we are looking for are our ad game IDs so we can implement the reward system.

With those Game ID’s from the placements page copied, lets make a new GameObject to manage our ads and get on with the coding!

To start off, we will be be needing to use the UnityEngine.Advertisements library and the following variables. the surfacingID is our choice from the Placements page however as this is a reward video, we will use that ad.

The Listener will callback whatever the target is, and initialize will well initialize the advertisement system itself.

To be honest, it was quite the struggle trying to get this working for me, but definitely was quite the learning experience. Showing the Ad was one thing, then what follows is figuring out if the Ad itself is ready, then setting if statements corresponding to if the Ad fully finished, was skipped or failed to play.

Click here to watch an ad and get some currency!

In this case I had set it to give the Player 100 Gold if watched after clicking the bright green button.

When testing the button (Don’t forget to add that!) in the inspector it wont actually play the ad, but will give you an example like this.

A tough one but it was worth it. On a side note, previously you would use the WWW method group to do ads and such but it is now obsolete.

See you next post!



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