55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace Managers
|
|
{
|
|
public class PlayerManager : MonoBehaviour
|
|
{
|
|
public PlayerData playerData;
|
|
public static PlayerManager Instance { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
public void TakeDamage(int damage)
|
|
{
|
|
playerData.health -= damage;
|
|
if (playerData.health <= 0) GameManager.Instance.EndGame();
|
|
}
|
|
|
|
public void Heal(int amount)
|
|
{
|
|
playerData.health += amount;
|
|
if (playerData.health > playerData.maxHealth) playerData.health = playerData.maxHealth;
|
|
}
|
|
|
|
public void AddExperience(int amount)
|
|
{
|
|
playerData.experience += amount;
|
|
if (playerData.experience >= 100)
|
|
{
|
|
playerData.level++;
|
|
playerData.experience = 0;
|
|
}
|
|
}
|
|
|
|
public void AddGold(int amount)
|
|
{
|
|
playerData.gold += amount;
|
|
}
|
|
|
|
public void AddItemToInventory(GameItem item)
|
|
{
|
|
GameManager.Instance.InventoryManager.AddItemToOpenSlot(item);
|
|
}
|
|
}
|
|
} |