I'm using google admob to show rewarded video ads in my game. Once the game is over, the play video button is enabled. If the user clicks on that, a panel opens asking "would you like to revive the player by watching an ad". There are two options, one is to hit "ok" and the other to cancel "x". The issue is that the I have to click on "ok" multiple times for the ad to show. Sometimes the ad doesn't show at all no matter how many times I click on "ok" .Here is the code I have in adscript:
public class AdScript : MonoBehaviour
{
string App_ID = "ca-app-pub-123454545~12345678";
string Video_Ad_Id = "ca-app-pub-3940256099942544/5224354917";
private RewardedAd rewardedAd;
void Start()
{
MobileAds.Initialize(App_ID);
}
public void RequestRewardBasedVideo()
{
this.rewardedAd = new RewardedAd(Video_Ad_Id);
AdRequest request = new AdRequest.Builder().Build();
this.rewardedAd.LoadAd(request);
this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
this.rewardedAd.OnAdOpening += HandleRewardedAdOpening;
this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;
}
public void ShowVideoRewardAd()
{
if (this.rewardedAd.IsLoaded())
{
this.rewardedAd.Show();
}
}
public void HandleRewardedAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardedAdLoaded event received");
}
public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args)
{
MonoBehaviour.print(
"HandleRewardedAdFailedToLoad event received with message: "
+ args.Message);
}
public void HandleRewardedAdOpening(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardedAdOpening event received");
}
public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
{
MonoBehaviour.print(
"HandleRewardedAdFailedToShow event received with message: "
+ args.Message);
}
public void HandleRewardedAdClosed(object sender, EventArgs args)
{
this.RequestRewardBasedVideo();
}
public void HandleUserEarnedReward(object sender, Reward args)
{
GameManager.instance.ReceiveReward();
}
}
The function RequestRewardBasedVideo() is added to the play video button and the ShowVideoRewardAd() is added to the "ok" button. The test ads show properly but the issue is that I have to hit the ok button multiple times for the ad to display. I'm not sure why this is happening. Can someone please help?