using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerStatManager : MonoBehaviour
{
public int playerMoney;
public Sprite playerSprite;
public float playerMaxHealth;
public float healthDecreaseSpeed; //1.12f is the minimum
public Color32 playerColour;
public int startMultiplier;
//public Color32 defaultColour;
public SaveState state;
//public SaveManager manager;
public int colourPlace;
public int shapePlace;
public static PlayerStatManager Instance
{
get;
set;
}
private void Awake()
{
if (GameObject.FindGameObjectsWithTag("Stats Manager").Length < 2)
{
DontDestroyOnLoad(this);
}
Load();
WaitToLoadSave();
Debug.Log(state);
Instance = this;
}
public void SaveToSaveState()
{
if (state == null)
{
Debug.Log("REEE");
Load();
}
else
{
state.playerMoney += playerMoney;
state.maxHealth = playerMaxHealth;
Save();
}
}
public void WaitToLoadSave()
{
playerMoney = state.playerMoney;
playerMaxHealth = state.maxHealth;
healthDecreaseSpeed = 1.11f;
}
public void Save()
{
PlayerPrefs.SetString("GameSave1", Helper.Serialize<SaveState>(state));
}
public void Load()
{
if (PlayerPrefs.HasKey("GameSave1"))
{
state = Helper.Deserialize<SaveState>(PlayerPrefs.GetString("GameSave1"));
}
else
{
state = new SaveState();
Save();
Debug.Log("No save file found");
}
}
}