Android并未还原非消耗性物品,因此我现在添加IAP侦听器,它正在还原我的非消耗性物品,但是现在当我购买消耗性物品时,它给了我两倍的感觉,就像我买了50黄金,但是却给了我100黄金一样,我认为发生这种情况是因为我为IAP侦听器使用了相同的脚本,但我不知道我要为IAP侦听器编写什么代码,我将放置一些图像和脚本,以便您可以更清楚地理解。
https://i.stack.imgur.com/ERV9r.png
https://i.stack.imgur.com/iVtXc.png
https://i.stack.imgur.com/FD8WO.png
https://i.stack.imgur.com/jQ8Rk.png
https://i.stack.imgur.com/MRqLj.png
public void OnPurchaseCompleted(Product product)
{
if(product != null)
{
switch (product.definition.id)
{
case "go50.ld":
PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 50);
GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
CloudVariables.ImportantValues[3] = PlayerPrefs.GetInt("Gold");
PlayGamesController.Instance.SaveCloud();
Debug.Log("Completed");
break;
case "gold.100":
PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 100);
GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
CloudVariables.ImportantValues[3] = PlayerPrefs.GetInt("Gold");
PlayGamesController.Instance.SaveCloud();
Debug.Log("Completed");
break;
case "gold.250":
PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 250);
GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
CloudVariables.ImportantValues[3] = PlayerPrefs.GetInt("Gold");
PlayGamesController.Instance.SaveCloud();
Debug.Log("Completed");
break;
case "gold.500":
PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 500);
GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
CloudVariables.ImportantValues[3] = PlayerPrefs.GetInt("Gold");
PlayGamesController.Instance.SaveCloud();
Debug.Log("Completed");
break;
case "gold.1000":
PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 1000);
GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
CloudVariables.ImportantValues[3] = PlayerPrefs.GetInt("Gold");
PlayGamesController.Instance.SaveCloud();
Debug.Log("Completed");
break;
case "remove.ads":
PlayerPrefs.SetInt("Remove", 1);
Destroy(AdManager.Instance.gameObject);
CloudVariables.ImportantValues[5] = PlayerPrefs.GetInt("Remove");
PlayGamesController.Instance.SaveCloud();
break;
default:
Debug.Log("Failed");
break;
}
}
}
答案 0 :(得分:0)
从Unity Console看来,您正在触发该事件两次,请检查在何处调用该事件。另外,在IAPButton屏幕快照中,您选择的黄金是100,而不是50,也许就是问题所在。