So I added a Reward based ad on my Unity Project, I want to reward the user with 300 coins for watching an ad but I'm getting duplicated rewards everytime. I think I know where is the problem, but I can't solve it!
I have this Start Function and a function to get the reward on my Ad Script:
void Start()
{
this.rewardBasedVideoAd = RewardBasedVideoAd.Instance;
rewardBasedVideoAd.OnAdLoaded += HandleOnAdLoaded;
rewardBasedVideoAd.OnAdOpening += HandleOnAdOpening;
rewardBasedVideoAd.OnAdClosed += HandleOnAdClosed;
rewardBasedVideoAd.OnAdRewarded += HandleOnAdRewarded;
MobileAds.Initialize(initStatus => { });
this.LoadRewardBasedAd();
}
public void HandleOnAdRewarded(object sender, Reward args)
{
PlayerPrefs.SetInt("coins", PlayerPrefs.GetInt("coins") + 300);
}
When you die in the game and want to start again I call SceneManager.LoadScene(0);
which is the only Scene I got! I think when I Load Scene the Start function is running again and adding another reward rewardBasedVideoAd.OnAdRewarded += HandleOnAdRewarded;
. I've tried calling rewardBasedVideoAd.OnAdRewarded -= HandleOnAdRewarded;
several times and in different moments but it didn't solve the problem.
If I restart the game n times in a row, when I watch an ad I will get the Reward n times! Can someone help me? Thank you in advance!