AdMob Reward Video Issue

Hi All,

So I’m having problems trying to figure out how to reward the player after watching the entire, not skipping, reward video ad from AdMob. I don’t know if there is a specific function that I can call that contains different cases like Unity Ads or what exactly I have to do to accomplish this.

Here is what I am using now:

public void AmShowRewardVideo ()
    {
        //Admob
        if (Admob.Instance ().isRewardedVideoReady())
        {
            Admob.Instance ().showRewardedVideo ();
            DataManagement.datamanagement.totalCoins += 100;
        }
        //UnityAds
        else if (Advertisement.IsReady("rewardedVideo"))
        {
            var options = new ShowOptions { resultCallback = HandleShowResult };
            Advertisement.Show("rewardedVideo", options);
        }
        DataManagement.datamanagement.SaveData ();
    }
    //Unity Ads Reward Video Result
    private void HandleShowResult(ShowResult result)    //Would need something similar to this for the AdMob video to solve my issue
    {
        switch (result)
        {
        case ShowResult.Finished:
            Debug.Log ("Unity reward ad shown");
            DataManagement.datamanagement.totalCoins += 100;
            break;

        case ShowResult.Skipped:
            Debug.Log("Unity reward ad skipped");
            break;

        case ShowResult.Failed:
            Debug.Log("Unity reward ad failed");
            break;
        }
        DataManagement.datamanagement.SaveData ();
    }

In case it can’t supply an AdMob video, it shows a Unity ads video (I believe). The Unity Ads HandleShowResualt function is exactly what I need to be doing for my AdMob video. How can I do this?

I haven’t used that plugin but isn’t there example code or documentation/guides?

There is, but I haven’t run across any that mention how to do this.

Download Admob Unity3d Plugin https://github.com/unity-plugins/Unity-Admob

Installation Admob Unity

Open your project in the Unity editor.
Navigate to Assets → Import Package → Custom Package.
Select the AdmobUnityPlugin.unitypackage file.
Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.

Init Admob Unity Plugin

Create A C# script ,drag the script to a object on scene , add the follow code in the script file

using admob;
Admob.Instance().initAdmob(“admob banner id”, “admob interstitial id”);//admob id with format ca-app-pub-279xxxxxxxx/xxxxxxxx
//Admob.Instance().initAdmob(“ca-app-pub-3940256099942544/2934735716”, “ca-app-pub-3940256099942544/4411468910”);

Here is the minimal code to create an admob video.

Admob.Instance().loadRewardedVideo(“ca-app-pub-3940256099942544/1712485313”);

Video need to be explicitly shown at an appropriate stopping point in your app, check that the video is ready before showing it:

if (Admob.Instance().isRewardedVideoReady()) {
Admob.Instance().showRewardedVideo();
}

Hope it helps you

1 Like