Reader small image

You're reading from  Unity 2022 Mobile Game Development - Third Edition

Product typeBook
Published inJun 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781804613726
Edition3rd Edition
Languages
Tools
Right arrow
Author (1)
John P. Doran
John P. Doran
author image
John P. Doran

John P. Doran is a passionate and seasoned Technical Game Designer, Software Engineer, and Author who is based in Incheon, South Korea. His passion for game development began at an early age. He later graduated from DigiPen Institute of Technology with a Bachelor of Science in Game Design. For over a decade, John has gained extensive hands-on expertise in game development working in various roles ranging from game designer to lead UI programmer working in teams consisting of just himself to over 70 people in student, mod, and professional game projects including working at LucasArts on Star Wars: 1313. Additionally, John has worked in game development education teaching in Singapore, South Korea, and the United States. To date, he has authored over 10 books pertaining to game development. John is currently a Technical Game Design Instructor at George Mason University Korea. Prior to his present ventures, he was an award-winning videographer.
Read more about John P. Doran

Right arrow

Advertising Using Unity Ads

When working on mobile titles, you need to think about how you are going to sell your game. Deciding on how to best sell a game can be difficult. Of course, you can sell your game for a price, and there is a possibility that it will be successful, but you’ll be limiting your audience numbers to a much lower amount. This could work well for a niche game, but if you’re trying to make a game with a broad appeal where you want to get as many players as possible to play your title, you may have some issues.

Having a price on the game can be a major hurdle in getting initial customers who will share the game via word of mouth and contribute to having more people play your game. To solve this potential issue, you do have the option of making your game free.

Afterward, you can give players the opportunity to purchase things or show advertisements when playing the game.

That’s not to say that having a bunch of advertisements in a free...

Technical requirements

This book utilizes Unity 2022.1.0b16 and Unity Hub 3.3.1, but the steps should work with minimal changes in future versions of the editor. If you would like to download the exact version used in this book, and there is a new version out, you can visit Unity’s download archive at https://unity3d.com/get-unity/download/archive. You can also find the system requirements for Unity at https://docs.unity3d.com/2022.1/Documentation/Manual/system-requirements.html in the Unity Editor system requirements section.

You can find the code files present in this chapter on GitHub at https://github.com/PacktPublishing/Unity-2022-Mobile-Game-Development-3rd-Edition/tree/main/Chapter06%20and%2007.

Setting up Unity Ads

Unity Ads is a video ad network for iOS and Android that can monetize your existing player base by showing ads. Unity Ads offers video ads that can be shown as either rewarded or non-rewarded placements. As the name suggests, rewarded ads will give the users a reward or incentive that will help them while playing the game. Before we can enable Unity Ads, we must first enable Unity’s Services suite. To activate Unity Services, you have to link your project to a Unity Services Project ID, which is how Unity can tell the difference between the different projects you are creating. So let’s see how to do that:

  1. Open the Services window by going to Window | General | Services or by pressing Ctrl + 0. This will open up the Unity Package Manager and will automatically select the Advertisement option:
Figure 7.1 – The Advertisement option in the Unity Package Manager

Figure 7.1 – The Advertisement option in the Unity Package Manager

  1. Click on the Install button and wait...

Displaying a simple ad

Advertisements are a possible way to generate revenue from players playing your game. As mentioned previously, Unity Ads has two different types of ads that we can display: simple and rewarded. Simple ads are easy to use, hence the name, and allow users to have simple full-screen interstitial ads. This can be really useful when moving between levels or perhaps when the player wants to restart the game. Let’s see how we can implement that feature now. Implement the following steps:

  1. To get started, we will need to add a new function to the UnityAdController class:
    /// <summary>
    /// Will get the appropriate Ad ID for the platform we
    /// are on
    /// </summary>
    /// <returns>A usable Ad ID</returns>
    private static string GetAdID()
    {
        string adID = "Interstitial_";
        if (Application.platform ==
            RuntimePlatform.IPhonePlayer...

Utilizing ad callback methods

The code we wrote for the LoadLevel function works perfectly fine when we go to the main menu of the game; however, if we dive into the game itself from the main menu, the game will still be going on in the background with the ad blocking the player from playing the game.

When running your app on an actual mobile device, the Unity project will pause while Unity Ads are shown. However, if you are testing in the Unity Editor, the game is not paused while the placeholder ads are shown. However, we can simulate that behavior ourselves using the Advertisement.ShowOptions class.

We will pause the game when an ad is shown and then resume the game once the ad is finished. To do so, perform the following steps:

  1. Let’s first open up the UnityAdController class and add the following variable and update the Start function to the following:
    /// <summary>
    /// A static reference to this object
    /// </summary>
    public static UnityAdController...

Opt-in advertisements with rewards

According to AdColony, the most recommended form of mobile game ad according to 58% of mobile developers is the rewarded video ad. By that, we’re referring to making ads an opt-in experience where players choose to see an ad and receive some kind of bonus in return. That way, users feel it’s a choice for them whether or not to watch the ad, and they feel more compelled to watch it because they will get something out of it.

Rewarded ad placements typically yield higher effective Cost Per 1000 Impressions (eCPMs) since they offer more engagement from users by allowing them to opt in before watching an ad in exchange for some in-game reward.

Note

If you’re interested in learning more about why reward ads are recommended, check out https://www-staging.adcolony.com/blog/2016/04/26/the-top-ads-recommended-by-mobile-game-developers/.

In our game, we could add the choice of restarting the game or seeing an ad to continue the...

Adding in a cooldown timer

Ads are great for developers; however, according to Unity’s Monetization FAQs, each user is only able to view 25 ads per day. With that in mind, we will likely want to make it so that players can only trigger ads every once in a while. This also has the benefit of making players want to come back to our game after a period of time.

Important note

For more information on Unity’s Monetization FAQs, check out https://docs.unity.com/ads/FAQ.html.

We will now implement a feature where our Continue option will only work once in a while with a short delay that we can easily customize if we like:

  1. To get started, go back to the UnityAdController script and add the following new variable to it, shown in the highlighted code:
    using System; // DateTime
    using UnityEngine;
    using UnityEngine.Advertisements; /* Advertisement class */
    public class UnityAdController : MonoBehaviour, IUnityAdsShowListener
    {
        /// <summary...

Summary

With that, we’ve got a good foundation of how to add ads to our game. Hopefully, you can see how easy it is to implement and can think of new ways to engage players to have the best experience possible. Over the course of this chapter, we discovered how to set up Unity Ads. We then saw how we could create simple ads and learned how to react to the player’s actions by implementing the IUnityAdsShowListener interface. Afterward, we saw how we can add rewards for players using opt-in advertisements in the game, and we added a cooldown to the system to make the game less annoying for players. With these newly acquired skills, you should be able to add advertisements and gain additional revenue from your own games that you create in the future.

Important note

By default, ads should be in test mode. It is against Unity Ads’ terms of service to distribute live ads to beta testers. If they were to click on or install any of the advertised games, their activity...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity 2022 Mobile Game Development - Third Edition
Published in: Jun 2023Publisher: PacktISBN-13: 9781804613726
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
John P. Doran

John P. Doran is a passionate and seasoned Technical Game Designer, Software Engineer, and Author who is based in Incheon, South Korea. His passion for game development began at an early age. He later graduated from DigiPen Institute of Technology with a Bachelor of Science in Game Design. For over a decade, John has gained extensive hands-on expertise in game development working in various roles ranging from game designer to lead UI programmer working in teams consisting of just himself to over 70 people in student, mod, and professional game projects including working at LucasArts on Star Wars: 1313. Additionally, John has worked in game development education teaching in Singapore, South Korea, and the United States. To date, he has authored over 10 books pertaining to game development. John is currently a Technical Game Design Instructor at George Mason University Korea. Prior to his present ventures, he was an award-winning videographer.
Read more about John P. Doran