Premium
Getting Started with Unity Monetization
Tutorial
Intermediate
30 Mins
Overview
Summary
Monetization of your Unity project through ads is a great way to generate revenue without charging your customers directly. A successful free ad-supported game will bring in many times the asking price of an ad-free game that must be purchased outright. Though Unity Ads is one of the Unity Services, it is not in the default Unity package and must be downloaded from the Asset Store.
When you first enable Unity Services for a project, you are asked to assign the project to an organization. By default, your account has one organization: your user name. Organization names must be unique. You can add (but not currently delete) more names, or rename an account at will, as long as the proposed new name is available. You might wish to have one organization for your solo projects, and one for your team.
Ads are shown in designated placement zones in your project. Rather than a literal scene or GameObject, a placement zone is just a mode defining how your players can interact with ads. Options include muting the audio and if or when they can skip the ad. For example, you wouldn’t want players to have the ability to skip a lucrative rewarded video. All projects in the Dashboard begin with two placement zones, video and rewardedVideo, for regular and incentivized video ads.
Topics we'll cover
Language
English
Recommended Unity Versions
2017.1 and Above
Tutorial
Getting Started with Unity Monetization
1.
Connecting A Project to Unity Ads
In the Unity Editor, from the Window dropdown select General > Services.
If you haven’t yet enabled any Unity Services for this project, you’ll be asked to create a Unity Project ID in the Services dashboard. (Figure 01) If this project has already been set up in your Dashboard, click “I already have a Unity Project ID,” and select your project’s name and organization. Otherwise, select the organization for this project and click Create. If you have Unity create your Project ID for you, it will set the name based on either the project name for desktop projects, or the Product Name in Player Settings for mobile projects.

2.
Enable Unity Ads
In the Services tab, click the toggle to enable Unity Ads. (Figure 02)

3.
Showing an ad
Showing an ad, from initialization to display, takes just a few lines of code. For this basic example, we’re only triggering the ad. The Unity Ads display has a built-in button to close the ad in Placement Zones where that’s allowed. Before you can trigger an ad, you need two pieces of information: your project’s Game ID for the platform(s) on which it will display ads, and the name of the video Placement Zone. You can find both of these in the Unity Dashboard.

4.
Login into the Unity Operate Dashboard
In your web browser of choice, go to https://operate.dashboard.unity3d.com/.
Click Projects on the left to view a summary of your project data, including ad revenue. Click on the name of the project you integrated in Step 1.

5.
Choose the Platform
From the left menu, select Monetization > Platforms. (Figure 03)

6.
Choose an ad placement
Make a note of your project’s Game IDs.
Click Placements, just above Platforms, to view or add to the video placements.
Click a placement name to view its settings. Click the arrow to the left of the placement name to return to the placement list. (Figure 04) When you’re ready, return to the Unity Editor.

7.
Create a script
Back in the Unity Editor, create or load a scene in which to play an ad.
From the GameObject dropdown, select Create Empty and name it AdDisplayObject.
Create a new script called AdDisplay and double click it to open in Visual Studio.

8.
Add to the script
To use Unity Ads, we need to reference the Advertisements namespace. On line 4, type:
using UnityEngine.Advertisements;
On lines 7 and 8, replace XXXXXXX with the proper Game IDs. Beginning on line 7, type:
public string myGameIdAndroid = "XXXXXXX"; public string myGameIdIOS = "XXXXXXX"; public string myVideoPlacement = "video"; public bool adStarted; private bool testMode = true;

9.
Modify the script
Since our Game ID is different between iOS and Android, we will use #if, #else, and  #endif directives to execute the code corresponding to the OS on which our game is running. In Start, beginning on line 17, type:
#if UNITY_IOS Advertisement.Initialize(myGameIdIOS, testMode); #else Advertisement.Initialize(myGameIdAndroid, testMode); #endif
Note that if this were a real game, #else could be extended to:
#else if UNITY_ANDROID
Doing so while running in the Unity Editor would disable our game from initializing Unity Ads, and the code is fine as is.
In Update, beginning on line 27, type:
if (Advertisement.isInitialized && Advertisement.IsReady(myVideoPlacement) && !adStarted) { Advertisement.Show(myVideoPlacement); adStarted = true; }

10.
Save script
AdDisplay is now complete. Save changes and return to the Unity Editor. (Figure 05)

11.
Add component and test
Add the Ad Display component to AdDisplayObject.
Enter Play mode. The test ad should display immediately. Exit Play mode.

12.
Conclusion
Unity Monetization is a quick, easy way to add a dependable revenue stream to your games. With careful placement, ads can seamlessly integrate into a player’s experience without feeling like it breaks the flow of fun.