【发布时间】:2019-03-20 12:51:58
【问题描述】:
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;
}
}
}
【问题讨论】: