How to access Unity Ads?

  • Preface

Unity Ads, the official advertising plug-in provided by Unity, is generally very convenient. Currently, it only supports Android and iOS ads, and the official has handled the calls between Unity and Android or iOS, so there is no need to write middleware for the platform. Interactive.  

1. Environmental preparation

There are currently two ways to integrate Ads SDK into a Unity project, using the integrated SDK service window or adding software packages from the asset store

2. Access process

1. Change File-> Build Settings to Android/iOS.

2. Click Ads on Window -> Services, and then enable SDK in the project.

https://unity3d.com/profiles/unity3d/themes/unity/images/services/unityads-guide/services.png

3. Add code

(1) Initialization

Add the UnityEngine.Advertisement namespace. Initialize the SDK early in the game's runtime life cycle, preferably Initialize at startup.

using UnityEngine.Advertisement;

public class UnityAdsScript : MonoBehaviour { 

    string gameId = "1234567";
    bool testMode = true;

    void Start () {
        Advertisement.Initialize (gameId, testMode);
    }
}

 (2) Display ordinary advertisements (ads can be skipped)

After enabling the service and creating a placement, you only need to call the Show method to display the advertisement.

Advertisement.Show ();

(3) Display reward ads (ads cannot be skipped)

Rewarding players for viewing advertisements can increase user engagement, resulting in higher revenue. For example, the game can reward players with in-game currency, consumables, extra life or experience. To reward players for completing video ads, use the callback method in the following example of HandleShowResult. Be sure to check if result is equal to ShowResult.Finished to verify that the user did not skip the ad.

    public void ShowRewardedAd()
    {
        if (Advertisement.IsReady("rewardedVideo"))
        {
            var options = new ShowOptions { resultCallback = HandleShowResult };
            Advertisement.Show("rewardedVideo", options);
        }
    }

    private void HandleShowResult(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                Debug.Log("The ad was successfully shown.");
                //
                // YOUR CODE TO REWARD THE GAMER
                // Give coins etc.
                break;
            case ShowResult.Skipped:
                Debug.Log("The ad was skipped before reaching the end.");
                break;
            case ShowResult.Failed:
                Debug.LogError("The ad failed to be shown.");
                break;
        }
    }

Call ShowRewardedAd(); where you need to trigger the ad.

 

  • Reference materials:

Quick start guide: https://unity3d.com/cn/services/ads/quick-start-guide

Integration guide: https://unityads.unity3d.com/help/unity/integration-guide-unity

Unity Ads Forum: https://forum.unity.com/forums/unity-ads.67/

Guess you like

Origin blog.csdn.net/hello_1995/article/details/87932553