Enemy 클래스 정의

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
		float health = 50.0f;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

체력 생성

void TakeDamage(int value)
{
    health -= value;
}
public float GetHealth()
{
    return health;
}

피해를 받았을 때 체력 감소 → TakeDamage()

변화한 체력을 확인 → GetHealth

Enemy생성 → sprite render → 스크립트 넣기