I am using unity ads for my mobile project. The thing is that I am adding a certain amount of money, say 50, after rewarded video ad finishes, but every time it ads a multiple of 50 to the money.
can someone Help me please
the reward variable = 50.
This is my ADManager script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Advertisements;
using UnityEngine;
public class AdManager : MonoBehaviour, IUnityAdsListener
{
private string playStoreID = "unknown";
private string interstitialAd = "video";
private string rewardedVideoAd = "rewardedVideo";
public bool isTestAd;
public static AdManager instance;
public int Reward;
bool once;
public GameObject button;
private void IntisializeAd()
{
instance = this;
Advertisement.Initialize(playStoreID, isTestAd);
}
// Start is called before the first frame update
void Start()
{
Advertisement.AddListener(this);
IntisializeAd();
}
public void InterstitialAd()
{
if(!Advertisement.IsReady())
{
return;
}
Advertisement.Show(interstitialAd);
}
public void RewardedAd()
{
if (!Advertisement.IsReady())
{
return;
}
Advertisement.Show(rewardedVideoAd);
}
// Update is called once per frame
void Update()
{
if (!Advertisement.IsReady())
{
button.SetActive(false);
return;
}else
{
button.SetActive(true);
}
}
public void OnUnityAdsReady(string placementId)
{
//throw new System.NotImplementedException();
}
public void OnUnityAdsDidError(string message)
{
//throw new System.NotImplementedException();
}
public void OnUnityAdsDidStart(string placementId)
{
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
once = false;
switch (showResult)
{
case ShowResult.Failed:
if (placementId == rewardedVideoAd)
{
Debug.Log("Ad Failed");
}
break;
case ShowResult.Skipped:
if (placementId == rewardedVideoAd)
{
Debug.Log("Ad skipped, Dont Reward");
}
break;
case ShowResult.Finished:
if(placementId == rewardedVideoAd)
{
if (once == false)
{
Debug.Log("Reward Player");
int ToatalMoney = PlayerPrefs.GetInt("Money", 0);
ToatalMoney += Reward;
PlayerPrefs.SetInt("Money", ToatalMoney);
once = true;
}
}
break;
}
}
}
↧