using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BaseController : MonoBehaviour
{
[SerializeField]
private Slider HPbar;
public float MaxHp = 30;
public float CurHp = 30;
void Start()
{
HPbar.value = (float)CurHp / (float)MaxHp; //hp 초기화
}
void Update()
{
UpdateHP();
}
private void UpdateHP()
{
HPbar.value = Mathf.Lerp(HPbar.value, (float)CurHp / (float)MaxHp,
Time.deltaTime * 10);
}
private void OnCollisionEnter2D(Collision2D other)
{
//Enemy Tag를 가진 오브젝트와 충돌했을 시
if (other.gameObject.CompareTag("Enemy"))
{
CurHp -= 1;
}
}
}