유니티/기능
유니티 Hp 관리
MJ_119
2024. 9. 20. 20:06
- HP 관리
health = MathF.Max(health - damage, 0);를 사용해서 체력이 0 이하로 안내려가게 한다.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Health : MonoBehaviour
{
[SerializeField] float health = 100f;
public void TakeDamaged(float damage)
{
health = MathF.Max(health - damage, 0);
print(health);
}
}