Rewarded video ads in Unity
Objective: Show how to set up rewarded video ads in Unity with Unity Ads
Making a game for mobile devices is great but if you don’t charge for the game then you need to make some money another way. A quick an easy way to do this is to enable Unity ads. This is a relatively pain free exercise.
First inside Unity you need to open the services window. Window -> general -> Services
Once that is turned on then you need to activate Unity ads in the new services window. Click on the Ads option and turn the ads on, then click open dashboard and this will open a new window that shows your Unity projects and you can view the monetization options for the game.
Unity has a new layout so, click on monetization and then ad units. I’ve filtered out iOS ad units, click on the ad unit you want to show in your game. For me, I want to show a rewarded ad on Android.
Copy the ad unit ID name by clicking on the copy to clipboard button. You will need to use this when creating the set up in script. Also copy the below android ID or iOS ID depending on what device you’re using.
Once you have created your new script the first thing you need to ad is the UnityEngine Advertisements namespace just like the usual Unity spaces.
I have created three variables, two from the Unity dashboard with the IDs and a bool for whether the game is in testmode. When testing, always make sure that you’re in test mode.
In the Start method you will need to Initialise the ads. To initialise the ad you need to use the device ID and the bool for whether you’re in test mode.
The method above is run when the watch ad button in game is clicked. It will make sure that the ad is ready to show by passing in the type of ad I want to show (rewardedAd). I then run a callback function that will run the below method and let me know whether the player finished the ad and if they do, then they shall be rewarded with 100 gems. Lucky them.
But if they skip or the ad didn’t play for another reason then no reward will be given.
And that is it for showing Unity ads in your game. There are some small adjustments to make once the game is on the relevant app store.
- Change the test bool to false so that your players can view actual ads.
- Need to add the app store ID to the Unity dashboard
You will only get this ID once the game is live on the store and you will find these IDs in the relevant stores dashboard.