Degulleo3D/Assets/KSH/DungeonPanelController.cs

32 lines
930 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DungeonPanelController : MonoBehaviour
{
[SerializeField] private Slider _bossHealthBar; // 0~1 value
[SerializeField] private Image[] _playerHealthImages; // color 값 white / black 로 조정
private int _countHealth = 0;
public void SetBossHealthBar(float hp) // hp: 0~100
{
float normalizedHp = hp / 100f; // 0~1 사이 값으로 조정
_bossHealthBar.value = normalizedHp;
}
// false 반환 시 사망 처리
public bool SetPlayerHealth()
{
if (_countHealth > _playerHealthImages.Length - 1) // out of index error 방지
{
return false;
}
_playerHealthImages[_countHealth].color = Color.black;
_countHealth++;
return _countHealth <= _playerHealthImages.Length - 1;
}
}