How to add multiple rewarded ads in Unity?

Unity rewarded video ads

- In this tutorial we will integrate multiple reward ads.

 Note : if you don't know how to activate Unity ads monetization Clock Here .

UNity Advertisement Version SDK 4 or higher

Exemple for two Rewarded Ads:
  • First create 2 Unity ads Id in unity Dashboard to us it in your Script.
  • create 2 button for your reward ads:

Unity rewarded video ads

Unity Ads script , Unity rewarded video ads

  • Now you must create a script to initialize the  unity Advertisement " AdsInitializer "

Copy the script:

using UnityEngine;
using UnityEngine.Advertisements;
 
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
    [SerializeField] string _androidGameId;
    [SerializeField] string _iOSGameId;
    [SerializeField] bool _testMode = true;
    private string _gameId;

    [SerializeField] RewardedAds rewardedAds;
   
 
    void Awake()
    {
        InitializeAds();
    }
 
    public void InitializeAds()
    {
        _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
            ? _iOSGameId
            : _androidGameId;
        Advertisement.Initialize(_gameId, _testMode, this);
    }
 
    public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
        rewardedAds.LoadAd();

    }
 
    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    }
}


  • Create the script for the Rewarded ads " RewardedAds  "
  • Copy the script ;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

public class RewardedAds : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] Button _showAdButton;
    [SerializeField] Button _showAdButton2;
    [SerializeField] string _androidAdUnitId = "Rewarded_Android";
    [SerializeField] string _androidAdUnitId2 = "Rewarded_Android2";
    [SerializeField] string _iOSAdUnitId = "Rewarded_iOS";
    string _adUnitId = null; // This will remain null for unsupported platforms
    string _adUnitId2 = null;
 
    void Awake()
    {  
        // Get the Ad Unit ID for the current platform:
#if UNITY_IOS
        _adUnitId = _iOSAdUnitId;
#elif UNITY_ANDROID
        _adUnitId = _androidAdUnitId;
        _adUnitId2 = _androidAdUnitId2;
#endif

        //Disable the button until the ad is ready to show:
        _showAdButton.interactable = false;
        _showAdButton2.interactable = false;
    }
 
    // Load content to the Ad Unit:
    public void LoadAd()
    {
        // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
        Debug.Log("Loading Ad: " + _adUnitId);
        Advertisement.Load(_adUnitId, this);

        Debug.Log("Loading Ad: " + _adUnitId2);
        Advertisement.Load(_adUnitId2, this);
    }
 
    // If the ad successfully loads, add a listener to the button and enable it:
    public void OnUnityAdsAdLoaded(string adUnitId)
    {
        Debug.Log("Ad Loaded: " + adUnitId);
           
//// Button 1 ////
        if (adUnitId.Equals(_adUnitId))
        {

            // Configure the button to call the ShowAd() method when clicked:
            _showAdButton.onClick.AddListener(ShowAd);
            // Enable the button for users to click:
            _showAdButton.interactable = true;

           
        }


        /// ad 2 ////        
        if (adUnitId.Equals(_adUnitId2))
        {
 
            // Configure the button to call the ShowAd() method when clicked:
            _showAdButton2.onClick.AddListener(ShowAd2);
            // Enable the button for users to click:
            _showAdButton2.interactable = true;
        }
    }

    public void OnUnityAdsAdLoaded2(string adUnitId2)
    {
       
    }
 
    // Implement a method to execute when the user clicks the button:
    public void ShowAd()
    {
        // Disable the button:
        _showAdButton.interactable = false;
        // Then show the ad:
        Advertisement.Show(_adUnitId, this);
    }
    public void ShowAd2()
    {
        // Disable the button:
        _showAdButton2.interactable = false;
        // Then show the ad:
        Advertisement.Show(_adUnitId2, this);
    }
 
    // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
    public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    {
        if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
        {
            Debug.Log("Unity Ads Rewarded Ad Completed");
            // Grant a reward.
            Debug.Log("you get reward");

            // Load another ad:
            Advertisement.Load(_adUnitId, this);
        }

        if (adUnitId.Equals(_adUnitId2) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
        {
            Debug.Log("Unity Ads Rewarded Ad Completed");
            // Grant a reward.
            Debug.Log("you get reward 2 ");

            // Load another ad:
            Advertisement.Load(_adUnitId2, this);
        }
    }
 
    // Implement Load and Show Listener error callbacks:
    public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
    }
 
    public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
    }
 
    public void OnUnityAdsShowStart(string adUnitId) { }
    public void OnUnityAdsShowClick(string adUnitId) { }
 
    void OnDestroy()
    {
        // Clean up the button listeners:
        _showAdButton.onClick.RemoveAllListeners();
        _showAdButton2.onClick.RemoveAllListeners();
    }
}

  • Save all and go to unity editor.
  • create a new Game object , name it  "AdsManager "


Unity Ads code

  • add the two scripts and fill the details:
Unity rewarded video ads

Now your Ads are ready .

For preview UNity Advertisement  SDK Version:

  • After creating two reawaded unity ad Id make a new script to manage the video rewarded ads.
  •  Name it " UnityAdsGetReward " , copy past the below Script .



  • UnityAdsGetReward.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

/* https://downloadfree-sf-games.blogspot.com/ By @SFGamesStudio*/

public class UnityAdsGetReward : MonoBehaviour, IUnityAdsListener
{
    string gameID = "0000000";
   
   
    string rewardedAdName = "Rewarded_Android";
   

    string hitAdName = "hint";


    bool rewarded = false;
    public bool testMode = false;
    public static UnityAdsGetReward instance;

   
private void Awake()
{
    if(instance == null)
    {
        instance = this;
    }
}
    // Start is called before the first frame update
    void Start()
    {
        Advertisement.AddListener(this);
        Advertisement.Initialize(gameID, testMode);
       
    }

    public void OnInitializationComplete()
    {
        Debug.Log("Unity Ads initialization complete.");
    }
 
    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    }


    public void ShowRewardedVideo()
    {
        // Check if UnityAds ready before calling Show method:
        if (Advertisement.IsReady(rewardedAdName))
        {
            Advertisement.Show(rewardedAdName);
        }
        else
        {
           
            Debug.Log("Video is not ready yet");
            Debug.Log("Rewarded video is not ready at the moment! Please try again later!");
        }
    }

   
    public void ShowHintdVideo()
    {
        // Check if UnityAds ready before calling Show method:
        if (Advertisement.IsReady(hitAdName))
        {
            Advertisement.Show(hitAdName);
        }
        else
        {
           

            Debug.Log(" Hit Video is not ready yet");
            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 (placementId == "Rewarded_Android" && showResult == ShowResult.Finished)
        {
           
            // Reward the user for watching the ad to completion.
           
           
       
        }
        if (placementId == "hint" && 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 == rewardedAdName)
        {
            // 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);
    }
}

  • Change the parts marked in red with the information for your ad units :

string gameID = "0000000";
   
   
string rewardedAdName = "Rewarded_Android";
   

string hitAdName = "hint";

 

  • Put the code for the reward in the place marked in green :
// Implement IUnityAdsListener interface methods:
    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        // Define conditional logic for each ad completion status:
        if (placementId == "Rewarded_Android" && showResult == ShowResult.Finished)
        {
            
            // Reward the user for watching the ad to completion.
                           
        }
        if (placementId == "hint" && showResult == ShowResult.Finished)
        {
            
            // Reward the user for watching the ad to completion.
                       
        }


use advertising include ago rewards interstitial days one need load advertisements using mediation admob allow may showing online market manager home card player players method app oct exchange select api level integration mar types facebook demo test link banner various share analysis 

reward admob unity unity ads unity rewarded video
ads unity ads documentation unity ads code
rewarded interstitial admob unity unity ads android unity ads callback
.