Unity3D Google admob:用户奖励两次(或更多)黑客攻击



我创建了一个每日奖励系统,玩家每天可以获得大约三个500个硬币,例如1/3个金币。我使用 Admob Unity 插件在玩家点击按钮获得 500 金币时向玩家显示奖励视频,该按钮可以点击 3 次,玩家每次观看奖励视频,他们都会获得 500 金币。

我的问题:

1:如果用户点击奖励按钮并第一次完整观看奖励视频,我的int将增加到1,玩家将获得500个硬币的奖励 - (原来如此,1/3与500个硬币(

2:如果用户第二次点击奖励按钮,但随后决定关闭奖励视频,则int不会增加,玩家也不会获得500个硬币的奖励-(仍然是500个硬币的1/3(

3:但是如果用户决定点击奖励按钮,然后决定完全观看新的奖励视频,int将增加2(而不是1(,玩家现在奖励1,000金币(而不是500( - (现在是3/3与1,500金币(

注意:此顺序不具体,用户可以从开始或在 int 达到 3/3 之前执行此方法,并且用户想要多少次都可以执行,只需关闭奖励视频很多时间(不完成视频(直到满意,然后观看奖励视频完整 3 次。

我不会包括我的每日奖励脚本,因为我认为它不会引起我的问题。 请有人帮我解决这个问题,谢谢!!!

这是我的奖励脚本:

{
public Admob ad;
public int clickInt = 0;
public Text clickText;
public Image coinImage;
public Button rewardButton;

void Awake()
{
if (PlayerPrefs.HasKey("amount"))
{
clickInt = PlayerPrefs.GetInt("amount");
}
}

void Start ()
{
#if UNITY_EDITOR
Debug.Log("Unable to play ad in the EDITOR");
if (clickInt == 1) { 
clickText.text = "1/3 Daily uses"; 
} else if (clickInt == 2) { 
clickText.text = "2/3 Daily uses"; 
} else if (clickInt >= 3) {
clickInt = 3;
}
if (clickInt == 3) {
clickText.text = "3/3 Daily uses";
}
#elif UNITY_ANDROID
if (clickInt == 1) { 
clickText.text = "1/3 Daily uses"; 
} else if (clickInt == 2) { 
clickText.text = "2/3 Daily uses"; 
} else if (clickInt >= 3) {
clickInt = 3;
}
if (clickInt == 3) {
clickText.text = "3/3 Daily uses";
}     
#endif
}
// Update is called once per frame
void Update()
{
#if UNITY_EDITOR
Debug.Log("Unable to play ad in the EDITOR");
if (clickInt == 1) { 
clickText.text = "1/3 Daily uses"; 
} else if (clickInt == 2) { 
clickText.text = "2/3 Daily uses"; 
} else if (clickInt >= 3) {
clickInt = 3;
}
if (clickInt == 3) {
clickText.text = "3/3 Daily uses";
}
#elif UNITY_ANDROID
ad = Admob.Instance ();
if (ad.isRewardedVideoReady ()) {
coinImage.enabled = true;
} else {
ad.loadRewardedVideo ("ca-app-pub-…………………/……………"); 
coinImage.enabled = false;
}
if (clickInt == 1) { 
clickText.text = "1/3 Daily uses";
rewardButton.interactable = true; 
} else if (clickInt == 2) { 
clickText.text = "2/3 Daily uses";
rewardButton.interactable = true;  
} else if (clickInt >= 3) {
clickInt = 3;
}
if (clickInt == 3) {
clickText.text = "3/3 Daily uses";
rewardButton.interactable = false; 
}     
#endif
}


public void Free_500_Coins()
{
#if UNITY_EDITOR
Debug.Log("Unable to play ad in the EDITOR");
clickInt += 1;
ShopManager.Playercurrency += 500;
#elif UNITY_ANDROID
if (ad.isRewardedVideoReady ()) {
Admob.Instance().interstitalRewardHandler += onInterstitalRewardVideoEvent;
coinImage.enabled = true;
ad.showRewardedVideo ();
} else {
ad.loadRewardedVideo ("ca-app-pub-............/..........."); 
coinImage.enabled = false;
}
#endif
}

void onInterstitalRewardVideoEvent(string eventNames, string msgs)
{
if (eventNames == "onRewarded")
{
Admob.Instance().interstitalRewardHandler -= onInterstitalRewardVideoEvent;
Debug.Log("Well Done! You got 500 coins");
clickInt += 1;
ShopManager.Playercurrency += 500;
Debug.Log("handler AdmobEventsHandler---" + eventNames + "   " + msgs);
}
}
public void OnDestroy()
{
Admob.Instance().interstitalRewardHandler -= onInterstitalRewardVideoEvent;
}
}```   

您必须从所有带有 + & - 的作业中删除"onInterstitalRewardVideoEvent",并在这些行下方添加。

void OnEnable() {
Admob.Instance().interstitalRewardHandler += onInterstitalRewardVideoEvent;
}
void OnDisable() {
Admob.Instance().interstitalRewardHandler -= onInterstitalRewardVideoEvent;
}

只需将if (ad.isRewardedVideoReady ()) {更改为if (ad.isRewardedVideoReady () && !coinImage.enabled) {即可。

向调用Free_500_Coins的按钮发送垃圾邮件将导致两次调用以添加处理程序。

最新更新