Unity - AdMob - Video reward only shows once.
Hello.. This problem is driving me crazy!
I have implemented AdMob in my game. When I open the ad for the first time, everything works just fine. The second time the ad will only show up (after some clicks on the button), but do not give the reward. When I restart the app, it will work again for one time.
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class continueGame : MonoBehaviour
{
public Transform playerspawn;
public GameObject player;
public GameObject spawner;
public static continueGame instance;
public GameObject[] platform;
private RewardBasedVideoAd continueAd;
private string RewardedDummyAdID = "ca-app-pub-3940256099942544/5224354917";
private void Start()
{
continueAd = RewardBasedVideoAd.Instance;
RequestRewardedAd();
continueAd.OnAdRewarded += HandleRewardBasedVideoRewarded;
continueAd.OnAdClosed += HandleRewardBasedVideoClosed;
}
public void RequestRewardedAd()
{
AdRequest req = new AdRequest.Builder().Build();
continueAd.LoadAd(req, RewardedDummyAdID);
}
public void ShowRewardedAd()
{
if (!continueAd.IsLoaded())
{
AdRequest req = new AdRequest.Builder().Build();
continueAd.LoadAd(req, RewardedDummyAdID);
continueAd.Show();
}
else
{
continueAd.Show();
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
continueTheGame();
RequestRewardedAd();
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
Debug.Log("Rewarded Video has closed.");
}
public void continueTheGame()
{
//revive player
foreach (GameObject go in platform)
{
go.SetActive(true);
}
player.SetActive(true);
player.transform.position = playerspawn.position;
killPlayer.instance.dead = false;
killPlayer.instance.playerDead = false;
killPlayer.instance.DeathUI.SetActive(false);
spawner.SetActive(true);
spawner.GetComponent<meteorSpawner>().manuelStart();
spawner.GetComponent<PowerupSpawner>().manuelStart();
spawner.GetComponent<EnemySpawner>().manuelStart();
spawner.GetComponent<rocketSpawner>().manuelStart();
spawner.GetComponent<ammoSpawner>().manuelStart();
powerups.instance.StartCoroutine("lessknockback");
gameObject.SetActive(false);
}
}
Answer by vsnappy1 · May 19, 2020 at 07:49 AM
[Solved] You need to unsubscribe from the events
Here is the code snippet
private void OnDestroy()
{
// Unsubscribe from reward video event
rewardBasedVideo.OnAdLoaded -= HandleRewardBasedVideoLoaded;
rewardBasedVideo.OnAdFailedToLoad -= HandleRewardBasedVideoFailedToLoad;
rewardBasedVideo.OnAdOpening -= HandleRewardBasedVideoOpened;
rewardBasedVideo.OnAdStarted -= HandleRewardBasedVideoStarted;
rewardBasedVideo.OnAdRewarded -= HandleRewardBasedVideoRewarded;
rewardBasedVideo.OnAdClosed -= HandleRewardBasedVideoClosed;
rewardBasedVideo.OnAdLeavingApplication -= HandleRewardBasedVideoLeftApplication;
}
If this does not work, try to remove RequestRewardedAd(); from HandleRewardBasedVideoRewarded function, and then try again
Hi did you manage that problem? Because i can't :/
Your answer
Follow this Question
Related Questions
Admob ads not working no matter waht 1 Answer
How to move the UI down when an ad banner appears 0 Answers
How can I call a method from async method? 2 Answers
Admob unnecessary permissions? 0 Answers
App closes immediately after opening 0 Answers