Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How do you give different rewards for rewarded ads

Discussion in 'Unity Ads' started by WhiteHotGames, Aug 2, 2020.

  1. WhiteHotGames

    WhiteHotGames

    Joined:
    Jun 11, 2018
    Posts:
    2
    Hi all,

    Hopefully there's a straightforward solution to this so I'll get straight to it.

    I've set up the Unity Ads script using UnityEngine.Advertisements instead of the old Monetization, but I've come across some minor issues with it that I'm struggling to overcome without some workaround.

    Using Monetization I could create an ad, have a callback for that ad and set the rewards to give at the end. In the new system you don't seem to set which callback the ad goes to, so there's just one for all ads, leaving me wondering how I can give different rewards.

    In my AdManager script there are 2 functions (pasted below) that are used, one to play the ad, one for the callback to give rewards. But if I can't set which callback is used by which ad, then I can only call "ShowRewardedVideo" from any ad button, and then it will always give the same rewards.

    Hopefully this make sense, below are the two functions within the AdManager script that I'm using. Any help is appreciated.

    Code (CSharp):
    1.  
    2. public void ShowRewardedVideo()
    3.     {
    4.         if (Advertisement.IsReady(myPlacementId))
    5.         {
    6.             Advertisement.Show(myPlacementId);
    7.         }
    8.         else
    9.         {
    10.             print("Rewarded video not ready");
    11.         }
    12.     }
    13.  
    14.     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    15.     {
    16.         // Define conditional logic for each ad completion status:
    17.         if (showResult == ShowResult.Finished)
    18.         {
    19.             print("Ad completed");
    20.         }
    21.         else if (showResult == ShowResult.Skipped)
    22.         {
    23.             print("Ad skipped");
    24.         }
    25.         else if (showResult == ShowResult.Failed)
    26.         {
    27.             print("Ad failed");
    28.         }
    29.     }
    30.  

    Here is an example of what I'm trying to do from my game:

    Rewarded Ad 1
    The player presses the button, watches the ad, and is given 100 coins

    Reward Ad 2
    The player presses the button, watches the ad, and is loaded into a new level

    It feels like the only way I can see it's intended to work is by adding a new placement ID for every rewarded ad you have in your game... which seems crazy as then surely you're juggling multiple ads to be ready to show, instead of 1/2.
     
    Last edited: Aug 2, 2020
  2. AdamColes4472

    AdamColes4472

    Unity Technologies

    Joined:
    Jul 20, 2020
    Posts:
    5
    Hi WhiteHotGames,

    In this new system the advertisement will call OnUnityAdsDidFinish() when the advertisement ends. When this is called the SDK will provide you with the placementId of the ad and an ad result.

    The ad result has 3 main states:
    • Finished - This is means the user watched the ad all the way through
    • Skipped - The user has pressed the skip button if it is available
    • Failed - The ad as failed to show correctly
    You should provide the player with a reward if the ad returns 'finished' (Line:19). You can use the placementId to determine what reward should be given for each placement. If you want multiple placementIds to have similar behavior you could edit the placementId's id to contain a key string that you could then look for.

    I hope that's helped
     
  3. kr-unity

    kr-unity

    Unity Technologies

    Joined:
    Jan 6, 2020
    Posts:
    133
    If you don't want to have multiple placements for different rewards, you could also selectively only add components as listeners when an ad is being shown for that reward. For example, if the 100 coins reward button is pressed, it can add itself as a listener as the ad is being shown, and then remove itself once the ad finishes. That way, you only ever have one listener registered at a time and bypass the issue of multiple callbacks firing.
     
  4. WhiteHotGames

    WhiteHotGames

    Joined:
    Jun 11, 2018
    Posts:
    2
    Thanks for your help guys, I'm going to review the options and see which works best for me.

    Out of curiosity, if I did add multiple placementIDs for give different rewards, would it affect the live game?
    For example, I currently have "rewardedVideo" as my rewarded ad placementID in my live game. If I were to name the placementIDs more appropriately based on where they're triggered, and edited this one, would it break in the live version as it's looking for "rewardedVideo", which no longer exists?
     
  5. AdamColes4472

    AdamColes4472

    Unity Technologies

    Joined:
    Jul 20, 2020
    Posts:
    5
    Too my knowledge changing the placementId in the dashboard without changing the id in the live game will cause ads to stop showing. For now I recommend you setup new placements and hook them up in the next update to your app. This will ensure you don't break anything for your current users.
     
    WhiteHotGames likes this.
unityunity