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";

void Start()
{
}

public void RequestRewardBasedVideo()
{

}

{
{
}
}

{
}

{
MonoBehaviour.print(
+ args.Message);
}

public void HandleRewardedAdOpening(object sender, EventArgs args)
{
}

{
MonoBehaviour.print(
+ args.Message);
}

public void HandleRewardedAdClosed(object sender, EventArgs args)
{
this.RequestRewardBasedVideo();
}

public void HandleUserEarnedReward(object sender, Reward args)
{
}
}


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?

My guess is that this:

public void ShowVideoRewardAd()
{
{
}
}


is just skipping over the call to Show over and over every time you tap the button, until the ad is actually loaded.

My suggestion is to not even show the option to watch an ad unless IsLoaded returns true. Alternatively, you can pop up a "please wait" dialog when the user taps to watch the video if IsLoaded is false, and wait for either HandleRewardedAdLoaded or HandleRewardedAdFailedToLoad is called.

• thanks a lot for the help...loading the ad on app launch is showing the ad everytime....one more question is there any way to load two different types of rewards like one for reviving the player and the other for adding 100 points to the score...I looked at the documentation, there isin't much information...in this function "public void HandleUserEarnedReward(object sender, Reward args) { GameManager.instance.ReceiveReward(); }", I can only have one reward....how do I add a second one like GameManager.instance.AddtoScore(); – single arrow games Aug 28 '20 at 8:50
• @singlearrowgames I'd suggest making a new post for that, as the answer is too large to fit into the margins. – Ed Marty Aug 28 '20 at 17:23
• I have created the new post - gamedev.stackexchange.com/questions/185637/… – single arrow games Sep 8 '20 at 11:12

I'll take a wild guess here (two guesses, actually).

The first guess is that the Ad framework is not yet completely initialized once you try to load your first ad. Based on the documentation, it seems you could pass a callback to the MobileAds.Initialize(); that would be called once the initialization is done. You would need to wait until the initialization is properly completed before requesting your first ads. At first sight, the documentation is pretty bad regarding how to do this exactly, so I suggest you dig a bit further to find more about how you could achieve this.

The second guess is that you're trying to load an ad before you set the event handlers. If we take another look at the documentation, it appears that they place the calls to

// Create an empty ad request.