'Adding to PlayPrefs is Inconsistent Unity Ads
I am trying to add coins to my PlayerPrefs after watching an Ad, but the first Reward is 100 coins and then it's getting way more and inconsisten. I have no Idea why this problem is occuring. Thanks
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
float coins = PlayerPrefs.GetFloat("coinPrefs");
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
PlayerPrefs.SetFloat("coinPrefs", coins + 100);
// Load another ad:
Advertisement.Load(_adUnitId, this);
}
}
Solution 1:[1]
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
PlayerPrefs.SetFloat("coinPrefs",PlayerPrefs.GetFloat("coinPrefs")+100);
// Load another ad:
Advertisement.Load(_adUnitId, this);
And If your number of coins is whole number it is better to set it as int
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | samke |
