Unity Ads

Hal Brooks
2 min readNov 13, 2021

--

Objective: Implement Unity reward ad for Android mobile game.

Click button to receive reward by watching a video.

Go to Unity Package Manger and install the Advertisement package shown below. Import the the package into the project.

Advertisement package for Unity.

Next open the Services from Unity menu window > general. Turn on ads and click on dashboard to create an Android rewards ad unit called OF_Shop_Ad using Unity Gaming Services, Monetization.

Unity services window with Ads on.

Create an empty game object, naming it AdsManager. Add a new C# script AdsManager to this object. This script inherits from IUnityAdsListener, which is an interface. This requires using UnityEngine.Advertisements to be declared. There are four variables: adUnitID identifies the ad to be used from Unity services, gameID is unique to the game, and _testMode and _adReady are private bools. The listener and initialization for the advertisement called in void Start.

AdsManager inherits from IUnityAdsListener.

The interface requires four methods, by contract. Their implementation is shown below. The latter two are not used but are required by the interface.

Contracted methods for IUnityAdsListener interface.

The method DisplayVideoAd() is shown below, and is used to start the ad when the player presses a button.

The Unity_Ad_Button is a child of the Shop_Panel, and setup as shown. The On Click() calls the DisplayVideoAd() method shown above via the AdManager script. Adjust the image color to be noticeably different than the other buttons. Change the text of the Text child object of this button to “Click here for 100G”.

A button is now available for the player to receive a reward by watching a video ad.

--

--

No responses yet