- Home /
Rewarded video ads rewarding player too much
using UnityEngine;
using System;
using GoogleMobileAds.Api;
using UnityEngine.UI;
public class ReklamRewardedVideo1 : MonoBehaviour
{
public Button reklamButton;
private int gemsReklam;
void Start()
{
MobileAds.Initialize("ca-app***************************************");
YeniReklamAl(null, null);
RewardBasedVideoAd reklamObjesi = RewardBasedVideoAd.Instance;
reklamObjesi.OnAdClosed -= YeniReklamAl;
reklamObjesi.OnAdClosed += YeniReklamAl; // Kullanıcı reklamı kapattıktan sonra çağrılır
reklamObjesi.OnAdRewarded -= OyuncuyuOdullendir;
reklamObjesi.OnAdRewarded += OyuncuyuOdullendir; // Kullanıcı reklamı tamamen izledikten sonra çağrılır
}
public void reklamReward()
{
reklamButton.enabled = RewardBasedVideoAd.Instance.IsLoaded();
RewardBasedVideoAd.Instance.Show();
reklamButton.enabled = true;
}
public void YeniReklamAl(object sender, EventArgs args)
{
RewardBasedVideoAd reklamObjesi = RewardBasedVideoAd.Instance;
AdRequest reklamIstegi = new AdRequest.Builder().Build();
reklamObjesi.LoadAd(reklamIstegi, "ca-app**********************************");
}
private void OyuncuyuOdullendir(object sender, Reward args)
{
gemsReklam = PlayerPrefs.GetInt("gems", 0);
PlayerPrefs.SetInt("gems",gemsReklam+25);
}
}
here is my rewarded video ads code. It's been called when player clicks a button. It's working properly. But my biggest problem is that: It never gives 25 gems as a reward. I want it to give 25 gems as reward. but by using this code , I get 50 gems as a reward at first rewardedads, 50 gems at second click. After that I go to a level and play game a little bit. I came back to this scene and watch 3rd rewardedads and it gives 125 gems, 4th reward is 175 gems.. It goes in that way. never gives 25 gems as reward and it is like giving rewards randomly. please help me to fix this. what am I missing here?
Answer by eraban · Nov 27, 2020 at 04:22 PM
@tolgaguducu Have you found the solution yet. I myself been having this problem. Please tell me the solution if you have solved it.
So here is the thing. I don't know I am new but this question have alrady been answerd its because when you lode the new seen every thing in the old seen gets Deleted except for your add manager. To fix this issue there is a code to stop the add manager once the seen is unloded. Right now i am searching for the same answer if I find it I will be back and copy pest the script here if I don't forget and if I find this again .
Answer by asukakhadkaiwa · Aug 09, 2021 at 02:57 PM
So here is the thing. I don't know I am new but this question have alrady been answerd its because when you lode the new seen every thing in the old seen gets Deleted except for your add manager. To fix this issue there is a code to stop the add manager once the seen is unloded. Right now i am searching for the same answer if I find it I will be back and copy pest the script here if I don't forget and if I find this again .
Answer by asuka0427_love · Aug 09, 2021 at 03:39 PM
i found the answer this is my another account i am going to copy pest his answer.. . . .
Hi @namanchanduka01, this is an easy fix and is down to how Unity handles scenes.
When Unity unloads a scene, it completely destroys everything included in that scene. When you load that scene again, it creates new versions of all your objects.
The Unity Ads SDK example code has the following:
void Start () {
Advertisement.AddListener (this);
Advertisement.Initialize (gameId, testMode);
}
... but it never has you remove the listener once the scene unloads. So your Ads code never gets destroyed, and you end up with multiple copies of it. Your game is rewarding extra coins because you accidentally have multiple leftover versions of your ads code running at the same time.
The fix is simple. Add this to your code:
private void OnDisable()
{
Advertisement.RemoveListener( this );
}
This will tell your ads code to remove itself as a listener when you change scenes, letting it be properly cleaned up by Unity.
As for your second question, you can find the Game IDs for each platform on the Operate dashboard for your project, in the project settings section. You do need to use the right ID for iOS and Android, or they won't work!
hope this is your answer;;