Unity Admob Rewarded Ads Tutorial Admob Unity Rewarded Video

Unity Admob Rewarded Ads Tutorial | Admob Unity Rewarded Video

Unity Admob Rewarded Ads Tutorial | Admob Unity Rewarded Video :- This comprehensive guide covers everything from setting up AdMob to implementing rewarded ad features, helping you create a rewarding experience for your players while optimizing your revenue. Perfect for developers looking to enhance user engagement and monetize their apps effectively. Follow along and unlock the full potential of rewarded ads in your Unity projects!

CONTACT US TO ADD 10 AD NETWORKS TO YOUR UNITY PROJECT – CHARGES APPLY

DOWNLOAD ADMOB PLUGIN

FULL ADMOB REWARDED ADS SCRIPT

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using System;

public class AdmobRewardedAds : MonoBehaviour
{

    private RewardedAd rewardedAd;

    public string rewardedId = "";

    public static AdmobRewardedAds Instance;

    void Start()

    {

        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
            LoadRewardedAd();
        });

    }

    void Awake()
    {
        Instance = this;

    }

    public void LoadRewardedAd()
    {
        // Clean up the old ad before loading a new one.
        if (rewardedAd != null)
        {
            rewardedAd.Destroy();
            rewardedAd = null;
        }

        Debug.Log("Loading the rewarded ad.");

        // create our request used to load the ad.
        var adRequest = new AdRequest();

        // send the request to load the ad.
        RewardedAd.Load(rewardedId, adRequest,
            (RewardedAd ad, LoadAdError error) =>
            {
                // if error is not null, the load request failed.
                if (error != null || ad == null)
                {
                    Debug.LogError("Rewarded ad failed to load an ad " +
                                   "with error : " + error);
                    return;
                }

                Debug.Log("Rewarded ad loaded with response : "
                          + ad.GetResponseInfo());

                rewardedAd = ad;
                RegisterEventHandlers(rewardedAd);
            });
    }

    public void ShowRewardedAd()
    {
        const string rewardMsg =
            "Rewarded ad rewarded the user. Type: {0}, amount: {1}.";

        if (rewardedAd != null && rewardedAd.CanShowAd())
        {
            rewardedAd.Show((Reward reward) =>
            {
                // TODO: Reward the user.
                Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
            });
        }
    }

    private void RegisterEventHandlers(RewardedAd ad)
    {
        // Raised when the ad is estimated to have earned money.
        ad.OnAdPaid += (AdValue adValue) =>
        {
            Debug.Log(String.Format("Rewarded ad paid {0} {1}.",
                adValue.Value,
                adValue.CurrencyCode));
        };
        // Raised when an impression is recorded for an ad.
        ad.OnAdImpressionRecorded += () =>
        {
            Debug.Log("Rewarded ad recorded an impression.");
            //HERE WILL GO THE REWARDED VIDEO CALLBACK!!!!
        };
        // Raised when a click is recorded for an ad.
        ad.OnAdClicked += () =>
        {
            Debug.Log("Rewarded ad was clicked.");
        };
        // Raised when an ad opened full screen content.
        ad.OnAdFullScreenContentOpened += () =>
        {
            Debug.Log("Rewarded ad full screen content opened.");
        };
        // Raised when the ad closed full screen content.
        ad.OnAdFullScreenContentClosed += () =>
        {
            Debug.Log("Rewarded ad full screen content closed.");
            LoadRewardedAd();
        };
        // Raised when the ad failed to open full screen content.
        ad.OnAdFullScreenContentFailed += (AdError error) =>
        {
            Debug.LogError("Rewarded ad failed to open full screen content " +
                           "with error : " + error);
            LoadRewardedAd();
        };
    }

}

In conclusion, integrating AdMob’s rewarded ads into your Unity project can significantly enhance both user engagement and revenue potential. By following this tutorial, you’ve equipped yourself with the knowledge to set up, configure, and optimize rewarded ads seamlessly. With these tools, you can create a compelling experience for your players while generating valuable income for your game or app. Keep experimenting and refining your ad strategy to ensure it aligns with your users’ needs and preferences, and watch as your project flourishes with the added benefits of rewarded ads.

***CHECK FULL VIDEO TUTORIAL***

Visit www.UnitySourceCode.store

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping