after collidning player with coin, score increases one unit. also when i touch a ui button it connects to online market and 2000 coins is transfered and bought successfully but the problem is that UI Text does not updates.
here are codes i use :
public class Playerscore : MonoBehaviour {
private int score;
public Text coinText;
void Start()
{
score = GlobalValues.money;
coinText.text = "" + score.ToString();
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Coin")
{
GlobalValues.money = GlobalValues.money + 1;
GetComponent<persistentData>().Save();
score++;
coinText.text = "" + score.ToString();
col.gameObject.SetActive (false);
}
}
}
public static class GlobalValues
{
public static int money = PlayerPrefs.GetInt ("score");
public class gameHandler : MonoBehaviour
{
private StoreEventHandler handler;
public Text GoldText;
private int gold;
void Start ()
{
gold = GlobalValues.money;
GoldText.text = "" + gold.ToString();
public void buyGold_2000(ShopItem item)
{
Debug.Log ("2000clicked");
StoreHandler .Instance .Purchase (item );
}
public void newGold2000(int Newgold2000)
{
gold = GlobalValues.money + Newgold2000 ;
GoldText.text = "" + gold.ToString();
}
public class StoreEventHandler : MonoBehaviour ,IStoreEventHandler
{
private gameHandler handler;
#region IStoreEventHandler implementation
void Start()
{
handler =gameObject .GetComponent <gameHandler >();
}
public void ProcessPurchase (ShopItem item)
{
if(item .SKU =="gold2000")
{
StoreHandler .Instance .Consume (item );
StartCoroutine (wait ());
}
public void OnConsumeFinished (ShopItem item)
{
if(item .SKU =="gold2000"){
handler .newGold2000 (2000);
}
public void OnGetPurchasesFinished (string allRawSKU, int length)
{
}
public void OnSetupSuccessful ()
{
}
public void OnProblemSettingUpIAB (string message, StoreErrorCodes errorCode)
{
throw new System.NotImplementedException ();
}
public void OnFailedToQueryInventory (string message, StoreErrorCodes errorCode)
{
throw new System.NotImplementedException ();
}
public void OnMissingToken (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
throw new System.NotImplementedException ();
}
public void OnSubscriptionNotAvilable (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
throw new System.NotImplementedException ();
}
public void OnFailedToConsumePurchase (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
throw new System.NotImplementedException ();
}
public void OnConsumeFinishedListenerError (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
throw new System.NotImplementedException ();
}
public void OnPurchaseFailed (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
}
public void OnPurchasePayloadVerificationFailed (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
throw new System.NotImplementedException ();
}
public void OnUserCancelled (string message, StoreErrorCodes errorCode, ShopItem item = null)
{
StartCoroutine (wait ());
}
public void OnUnknownError (StoreErrorCodes errorCode, string message = "", ShopItem item = null)
{
throw new System.NotImplementedException ();
}
#endregion
IEnumerator wait(){
yield return new WaitForSeconds (1);
}