I have something that really annoys me and I hope some of you could help me with it. I have been using Player Prefs and so far as far as customisation purchasing is concerned it has worked very well. However, when I have attempted to use this with a game mode for purchase. Every time I press the button it decreases my coins (my micro transaction system). I would like it to make a one time purchase. Thanks in advance. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CustomisePayment : MonoBehaviour {
private int CoinCounter;
private string PrefPurchaseHoleInAWall;
// Use this for initialization
void Start () {
PlayerPrefs.SetString ("PrefPurchaseGameMode",PrefPurchaseHoleInAWall);
CoinCounter = PlayerPrefs.GetInt ("CoinCount",CoinCounter);
if (PlayerPrefs.GetString ("PrefPurchaseGameMode", PrefPurchaseHoleInAWall) == "PurchasedGameMode") {
PrefPurchaseHoleInAWall = "PurchasedGameMode";
PlayerPrefs.SetString ("PrefPurchaseGameMode", PrefPurchaseHoleInAWall);
} else {
PrefPurchaseHoleInAWall="NotPurchasedGameMode";
PlayerPrefs.SetString ("PrefPurchaseGameMode",PrefPurchaseHoleInAWall);
}
}
// Update is called once per frame
void Update () {
}
public void OnPressPurchaseHoleInWall(){
if (PlayerPrefs.GetString ("PrefPurchaseGameMode",PrefPurchaseHoleInAWall) != "PurchasedGameMode") {
if (CoinCounter >= 300) {
CoinCounter -= 300;
PlayerPrefs.SetInt ("CoinCount", CoinCounter);
PrefPurchaseHoleInAWall = "PurchasedGameMode";
PlayerPrefs.SetString ("PrefPurchaseGameMode",PrefPurchaseHoleInAWall);
Debug.Log ("Purchased");
}
}
if (PlayerPrefs.GetString ("PrefPurchaseGameMode",PrefPurchaseHoleInAWall) == "PurchasedRed") {
Debug.Log ("Not Purchased");
}
}
}