46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PlayerHealth : Health, IDamageable
|
|
{
|
|
[SerializeField] PlayerStat _pstat;
|
|
|
|
public Image UI_HPBar { get; private set; }
|
|
public Image UI_MPBar { get; private set; }
|
|
public Image UI_StaminaBar { get; private set; }
|
|
|
|
public PlayerStat Pstat { get { return _pstat; } }
|
|
|
|
private void Awake()
|
|
{
|
|
_pstat = GetComponent<PlayerStat>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
maxHp = _pstat.MaxHp;
|
|
currentHp = _pstat.MaxHp;
|
|
|
|
UI_HPBar = GameManager.Instance.InGameUI.UserHealth.UI_HPBar;
|
|
UI_MPBar = GameManager.Instance.InGameUI.UserHealth.UI_MPBar;
|
|
UI_StaminaBar = GameManager.Instance.InGameUI.UserHealth.UI_StaminaBar;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UI_HPBar.fillAmount = (float)currentHp / (float)maxHp;
|
|
}
|
|
|
|
public void TakeDamage(int damage)
|
|
{
|
|
ChangeHP(currentHp - Mathf.Clamp(damage, 0, currentHp));
|
|
}
|
|
|
|
public void TakeDamage(int damage, Transform source)
|
|
{
|
|
TakeDamage(damage);
|
|
}
|
|
|
|
public Transform GetTransform() => transform;
|
|
}
|