- Home /
UnityAds Use both Rewarded and Interstitial Video Ad
Hi everyone, I implemented Unity Ads according to the Manual and it is working. However, I try to use both Reward Video Ad and Interstitial Video Ad and there seems to be an Override, because both functions reward the Player. For testing the Functionality, I have two Buttons in my scene, the first one is connected to DisplayInterstitialAD()
and the second one is connected to DisplayRewardVideoAD()
. No matter which one is called, they both call OnUnityAdsDidFinish(...)
and thus the Reward Function. Is it wrong to implement both Methods in one Script? I know one Workaround would be to use a bool connected to the buttons, but I think that I implemented it wrong and Unity has another solution for combining the two ad formats, right?
This is the Script:
using UnityEngine;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour, IUnityAdsListener
{
public static AdManager instance;
public bool TestMode = true;
string game_ID = "xxxxxxx";
string myPlacementId = "rewardedVideo";
private void Start()
{
Advertisement.Initialize(game_ID, TestMode);
Advertisement.AddListener(this);
}
public void DisplayInterstitialAD()
{
Advertisement.Show();
}
public void DisplayRewardVideoAD()
{
Advertisement.Show(myPlacementId);
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
PayReward_1();
}
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 PayReward_1()
{
//Paying the Reward to the Player
}
}
Answer by Kofiro · Jan 04, 2021 at 09:55 PM
Within your OnUnityAdsDidFinish method do this
if(placementId.Equals(myPlacementId))
{
if(showResult == ShowResult.Finished)
{
PayReward_1();
}
}
Thank you, but that would be the same as using a bool right? The problem with that solution is that the Reward Ad is skippable, while the Interstitial is not. I am looking for a solution that differentiate between the skippable Reward Video and the unskippable Interstitial. I always worked with Google's Admob where you have two different Ad Objects for those two Formats, way easier to handle.
Answer by afot2020 · Jan 05, 2021 at 09:58 AM
Ok I found the solution. I have to use two different Placement IDs, which I generate in the Unity Dashboard. And then I initialize and call them like this:
string PlacementId_reward = "rewardedVideo";
string PlacementId_interstitial = "interstitial";
public void DisplayInterstitialAD()
{
Advertisement.Show(PlacementId_interstitial);
}
public void DisplayRewardAD()
{
Advertisement.Show(PlacementId_reward);
}
For detecting the Reward I can then use the solution of Kofiro posted above. Thanks!
Your answer
Follow this Question
Related Questions
unity ads only shows up to 8 ads in a row in my app 1 Answer
No UnityAds displaying in AppStore version? 0 Answers
Error when building Game 0 Answers
Is there some way we can Place Ads in Games Using Unity Video Component 0 Answers
What could cause Unity Ads to crash after a couple of reward videos? 0 Answers