2025-10-15 21:31:13 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2025-10-20 09:02:15 +08:00
|
|
|
using Script.Gameplay.Interface;
|
2025-10-15 21:31:13 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using Core;
|
2025-10-18 15:41:43 +08:00
|
|
|
using Script.Gameplay.Global;
|
2025-10-15 21:31:13 +08:00
|
|
|
|
2025-10-20 10:12:07 +08:00
|
|
|
namespace Script.Gameplay.Player
|
2025-10-15 21:31:13 +08:00
|
|
|
{
|
2025-10-18 15:41:43 +08:00
|
|
|
public class PlayerController : MonoBehaviour, IDamageable
|
2025-10-15 21:31:13 +08:00
|
|
|
{
|
2025-10-18 15:41:43 +08:00
|
|
|
[SerializeField] private int MaxHealth = 100;
|
|
|
|
|
|
|
|
private int currentHealth;
|
|
|
|
public int CurrentHealth
|
|
|
|
{
|
|
|
|
get => currentHealth;
|
|
|
|
private set
|
|
|
|
{
|
|
|
|
currentHealth = value;
|
|
|
|
OnHealthChanged?.Invoke(currentHealth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public event Action<int> OnHealthChanged;
|
|
|
|
public event Action OnDeath;
|
|
|
|
|
2025-10-15 21:31:13 +08:00
|
|
|
private PlayerMoveController playerMoveController;
|
|
|
|
private PlayerCameraController playerCameraController;
|
2025-10-18 09:00:18 +08:00
|
|
|
|
2025-10-15 21:31:13 +08:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
playerMoveController = GetComponent<PlayerMoveController>();
|
|
|
|
playerCameraController = GetComponent<PlayerCameraController>();
|
2025-10-18 15:41:43 +08:00
|
|
|
|
2025-10-15 21:31:13 +08:00
|
|
|
CurrentHealth = MaxHealth;
|
2025-10-18 09:00:18 +08:00
|
|
|
|
2025-10-17 15:10:19 +08:00
|
|
|
ControllerLocator.Instance.Register(this);
|
2025-10-15 21:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2025-10-18 15:41:43 +08:00
|
|
|
OnDeath += GameFlowManager.Instance.RestartGame;
|
2025-10-15 21:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void TakeDamage(int damage)
|
|
|
|
{
|
|
|
|
CurrentHealth -= damage;
|
2025-10-18 15:41:43 +08:00
|
|
|
if (CurrentHealth <= 0)
|
|
|
|
{
|
|
|
|
CurrentHealth = 0;
|
|
|
|
OnDeath?.Invoke();
|
|
|
|
}
|
2025-10-15 21:31:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Heal(int heal)
|
|
|
|
{
|
|
|
|
CurrentHealth += heal;
|
|
|
|
if (CurrentHealth > MaxHealth)
|
|
|
|
{
|
|
|
|
CurrentHealth = MaxHealth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|