The problem is that whenever e.g. I’m watching an interstacial ad I get the reward from all “active” scripts with OnUnityAdsDidFinish in it. Which runs all my rewards from ALL the scripts with a OnUnityAdsDidFinish in it, even though I have separate placementIds in the different scripts.
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult) {
if (showResult == ShowResult.Finished)
{
MoneyManager.Instance.AddMoney(20);
Debug.Log("AD ROLL TWO COMPLETE");
}
else if (showResult == ShowResult.Skipped)
{
}
else if (showResult == ShowResult.Failed)
{
}
}
If I have two separate scripts with different placementIDs with addmoney(20) I will get 40 in value instead of 20 as I want.
You need to be checking the placementId in your OnUnityAdsDidFinish callback. Every listener is called when an ad becomes ready, starts, finishes, etc. and the placementId is sent so that you can determine which placement Id the callback is referring to.
For everyone else having the same issue, what I did is to make it so you add Listener when you press the button and remove it when the ad is succesful. This way you avoid having all scripts waiting for an Ad to pop.
Idk if its the best way but it works so
I would not recommand adding listeners on the fly, especially on user interaction. If the user spams the button, it may stack your listener several times and this can actually slow your interface because all the listeners copies will be triggered in the same time.
The scripts that dont need the listener will not wait for the ad to pop to do their job, in fact, listeners are kind of asynchronous tasks.