Skip to content

Instantly share code, notes, and snippets.

@suakig
Created May 12, 2015 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suakig/1d96b4cc9b498b60fc03 to your computer and use it in GitHub Desktop.
Save suakig/1d96b4cc9b498b60fc03 to your computer and use it in GitHub Desktop.
DeleGateAction.cs
using UnityEngine;
using System.Collections;
using System;
public class DeleGateAction
{
private const string COIN_KEY = "Coin";
public static Action<int> OnCoinChange = delegate {};
public static int Get()
{
return PlayerPrefs.GetInt (COIN_KEY, 0);
}
public static bool Add(int coin)
{
if (coin < 0) {
return false;
}
CoinChange (Get () + coin);
return true;
}
public static bool Sub(int coin)
{
if (coin < 0) {
return false;
}
if (Get () - coin < 0) {
return false;
}
CoinChange (Get () - coin);
return true;
}
private static void CoinChange(int coin)
{
PlayerPrefs.SetInt (COIN_KEY, coin);
PlayerPrefs.Save ();
OnCoinChange (PlayerPrefs.GetInt (COIN_KEY, 0));
}
public static void CoinChange()
{
OnCoinChange (PlayerPrefs.GetInt (COIN_KEY, 0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment