HMS Ads Kit | Unity
Hi everyone,
In this article, I will mention how to use HMS Ads Kit on Unity.
You can reach the plugins with the link below.
Currently, this plugin supports some HMS Kits. (HMS Unity Plugin v1.1.2)
- Account Kit
- In App Purchases : Consumable and non consumables
- Ads Kit : Interstitial and rewarded videos
- Push Kit
- Game Leaderboards and Achievements
First of all, we should create a unity project and import plugin into unity project. If you do not have enough information about HMS Unity plugin integration, I recommend you to read this article. HMS Unity Plugin Integration
After integration HMS Unity Plugin, you can see some folders.
Let’s go to Assets / Huawei / Demos path, open AdsDemo scene and run it on Huawei phone to check ads kit.
In this demo scene, there are two buttons for 2 ad types as seen in the picture above.
Let’s start to examine this demo scene;
To use ads kit, we need to use AdsManager Prefabs and we need to create an own script(AdsDemoManager.cs) as you see in demo scene.
In AdsDemo scene, there is AdsManager prefab. Because we should access the methods of ads kit through AdsManager prefab. And also AdsManager prefab contains ads sciprts. (Assets/Huawei/Scripts/Ads)(Reward Ad Manager.cs, Interstital Ad Manager.cs)
For onclick trigger, we use the methods in AdsDemoManager script. And we create this AdsDemoManager script by using the scripts inside the AdsManager (Reward Ad Manager.cs, Interstital Ad Manager.cs)
For now, this plugin supports two types of ads kit. (Interstitial and rewarded videos)
Rewarded Ad
Rewarded ads are full-screen video ads that reward users for watching.
To integrate the rewarded ad into the unity project, firstly, you need to add AdsManager prefab or RewardAdManager.cs file into scene.
And then we need to create a C# script(e.g. AdsKitReward.cs), to call ad and check its status. In this script we will initialize RewardAdManager and we will call methods.
And let’s make the necessary configuration. We use the “testx9dtjwj8hp” id to test at rewarded ad. And then set the methods we want to use.
Let’s write the method to check if the user is watching the whole ad.
Let’s write a method to show the advertisement on the screen.
Also you can use the following methods to check the status of the rewarded ad.
OnRewardAdClosed()
OnRewardAdFailedToShow()
OnRewardAdOpened()
OnRewarded()
LoadNextRewardedAd()
ShowRewardedAd()
Interstitial Ad
Interstitial ads are full-screen ads that cover the interface of an app. Such an ad is displayed when a user starts, pauses, or exits an app, without disrupting the user’s experience.
In general, the integration of these two ad types is the same.
To integrate the Interstitial ad into the unity project, firstly you need to add AdsManager prefab or InterstitalAdManager.cs file into scene.
And then we need to create a C # script(e.g. AdsKitInterstital.cs), to call ad and check its status. In this script we will initialize InterstitalAdManagerand we will call methods.
And let’s make the necessary configuration. We use the “testb4znbuh3n2” id to test at rewarded ad. And then set the methods we want to use.
Let’s write the method of controlling the user’s exit from the advertisement.
Let’s write a method to show the advertisement on the screen.
We have more methods to check the interstitial ad status and to take action accordingly. You can see these methods below.
OnAdClicked()
OnAdClosed()
OnAdFailed()
OnAdImpression()
OnAdLeave()
OnAdLoaded()
OnAdOpened()
For example, you want to check if the user has closed the rewarded ad. You should set the OnRewardAdClosed method as you see.
I hope this article was useful.
Finally, you can ask the problems that you encountered from the Huawei Developer forum page and see the questions that were answered previously.