탑뷰 슈팅 게임 미니 프로젝트
This commit is contained in:
53
Assets/Scripts/Character.cs
Normal file
53
Assets/Scripts/Character.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Character : MonoBehaviour
|
||||
{
|
||||
// [Range(0 , 3)]
|
||||
public float MaxHP = 3;
|
||||
public GameObject HPGauge;
|
||||
|
||||
float HP;
|
||||
|
||||
private float HPMaxWidth;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
HP = MaxHP;
|
||||
|
||||
if (HPGauge != null)
|
||||
{
|
||||
HPMaxWidth = HPGauge.GetComponent<RectTransform>().sizeDelta.x;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initalize()
|
||||
{
|
||||
HP = MaxHP;
|
||||
}
|
||||
|
||||
/*
|
||||
* 살아있으면 true를 리턴한다.
|
||||
*/
|
||||
public bool Hit(float damage)
|
||||
{
|
||||
HP -= damage;
|
||||
|
||||
if (HP < 0)
|
||||
{
|
||||
HP = 0;
|
||||
}
|
||||
|
||||
if(HPGauge != null)
|
||||
{
|
||||
HPGauge.GetComponent<RectTransform>().sizeDelta = new Vector2(HP/MaxHP * HPMaxWidth, HPGauge.GetComponent<RectTransform>().sizeDelta.y);
|
||||
}
|
||||
return HP > 0;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user