how to setup unity ads in mobile game

Configuring your project

Setting build target

Configure your project for supported platforms using build setting set build target to android or iOS


Installing Unity ads by package manager

1. in editor click Windows and then select package manager
Navigating package manager in unity

2. Select advertisement package from list and and select recent verified version of unity ads and click on install or update button.
Installing unity ads


Creating Placement

Open Developer Dashboard and use operate tab and create a new project or use existing one and then open it
developer dashboard of unity

select your project and here you will find all you need
ad placement in unity ads

Expand monetization and select placements 

monetization unity ads

On selecting placement you find here your Game Ids so just remember that we will use them later.



game ids in unity ads dashboard


 at right right side of game ids there will be your placements
Two placement of video and rewarded video are created there 
and if you want other placement then click on add placement
and then click on any placement video or rewarded video the here you will find your placement id.
placement id in unity ads

In unity ads there are three types of placement ids
1. Non - rewarded video ads to show basic interstitial ads or promotional content. Non-rewarded Placements allow players to skip the ad after a specified period of time.  

2. Rewarded video ad to allow players to opt-in to viewing ads in exchange for incentives. Rewarded Placements do not allow the player to skip the ad.

3. Banner ad placement 

you can use whatever you want

Banner ad example script

In your Placement script header, declare the UnityEngine.Advertisements namespace, which contains the Banner class. Next, initialize the SDK and use Banner.Show to display a banner ad.
using System.Collections; using UnityEngine; using UnityEngine.Advertisements; public class BannerAdScript : MonoBehaviour { public string gameId = "1234567"; public string placementId = "bannerPlacement"; public bool testMode = true; void Start () { Advertisement.Initialize(gameId, testMode); StartCoroutine(ShowBannerWhenInitialized()); } IEnumerator ShowBannerWhenInitialized () { while (!Advertisement.isInitialized) { yield return new WaitForSeconds(0.5f); } Advertisement.Banner.Show (placementId); } }

Banner ad position
Advertisement.Banner.SetPosition (BannerPosition.TOP_CENTER);


Interstitial display ad script example

using UnityEngine; using UnityEngine.Advertisements; public class InterstitialAdsScript : MonoBehaviour { string gameId = "1234567"; bool testMode = true; void Start () { // Initialize the Ads service: Advertisement.Initialize(gameId, testMode); } public void ShowInterstitialAd() { // Check if UnityAds ready before calling Show method: if (Advertisement.IsReady()) { Advertisement.Show(); } else { Debug.Log("Interstitial ad not ready at the moment! Please try again later!"); } } }

call ShowInterstitialAd() function where you want to show ad.

Rewarded Video Example Script
using UnityEngine; using UnityEngine.Advertisements; public class RewardedAdsScript : MonoBehaviour, IUnityAdsListener { string gameId = "1234567"; string myPlacementId = "rewardedVideo"; bool testMode = true; // Initialize the Ads listener and service: void Start () { Advertisement.AddListener (this); Advertisement.Initialize (gameId, testMode); } public void ShowRewardedVideo() { // Check if UnityAds ready before calling Show method: if (Advertisement.IsReady(myPlacementId)) { Advertisement.Show(myPlacementId); } else { Debug.Log("Rewarded video is not ready at the moment! Please try again later!"); } } // Implement IUnityAdsListener interface methods: public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) { // Define conditional logic for each ad completion status: if (showResult == ShowResult.Finished) { // Reward the user for watching the ad to completion. } else if (showResult == ShowResult.Skipped) { // Do not reward the user for skipping the ad. } else if (showResult == ShowResult.Failed) { Debug.LogWarning ("The ad did not finish due to an error."); } } public void OnUnityAdsReady (string placementId) { // If the ready Placement is rewarded, show the ad: if (placementId == myPlacementId) { // Optional actions to take when the placement becomes ready(For example, enable the rewarded ads button) } } public void OnUnityAdsDidError (string message) { // Log the error. } public void OnUnityAdsDidStart (string placementId) { // Optional actions to take when the end-users triggers an ad. } // When the object that subscribes to ad events is destroyed, remove the listener: public void OnDestroy() { Advertisement.RemoveListener(this); } }

Use ShowRewardedVideo() function to show rewarded video ad
use OnUnityAdsDidFinish() for custom results.




Popular posts from this blog

Positioning GameObjects in unity editor

Creating count down timer in unity by c# script

Changing Image in unity by C# script