using System; using UnityEngine; public static class GameConstants { private const string CashKey = "Cash"; private const string CarSelectedKey = "CarSelected"; private const string CarUnlockedPrefix = "CarUnlocked_"; private const string CarColorIndexKey = "CarColorIndex"; public static event Action OnCashChanged; private const string PlayerNameKey = "PlayerName"; public static string PlayerName { get => PlayerPrefs.GetString(PlayerNameKey, "You"); set => PlayerPrefs.SetString(PlayerNameKey, value); } public static int CarColorIndex { get => PlayerPrefs.GetInt(CarColorIndexKey, 0); set => PlayerPrefs.SetInt(CarColorIndexKey, value); } public static int Cash { get => PlayerPrefs.GetInt(CashKey, 0); set { PlayerPrefs.SetInt(CashKey, value); OnCashChanged?.Invoke(value); // 🔔 Notify all listeners } } public static int CarSelected { get => PlayerPrefs.GetInt(CarSelectedKey, 0); set => PlayerPrefs.SetInt(CarSelectedKey, value); } public static bool IsCarUnlocked(int index) { return PlayerPrefs.GetInt(CarUnlockedPrefix + index, index == 0 ? 1 : 0) == 1; } public static void UnlockCar(int index) { PlayerPrefs.SetInt(CarUnlockedPrefix + index, 1); } }