상세 컨텐츠

본문 제목

유니티 Hp 관리

유니티/기능

by 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);
    }
}

 

관련글 더보기