PBG2H23ABR_PBG2H23AKL_PMC_P.../Plunderblock/Assets/Scripts/ScriptsKevin/Enemy.cs

38 lines
849 B
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Enemy : MonoBehaviour
{
private bool alive = true;
public DataEnemy dataEnemy;
public void checkAlive(bool alive){
if(!alive){
GameObject.Destroy(this.gameObject);
}
}
public void takeDamage(float bulletDamage){
dataEnemy.health = dataEnemy.health - bulletDamage;
if(dataEnemy.health <= 0){
alive = false;
}
}
private void OnCollisionEnter(Collision collision){
DataBullet bulletData = collision.gameObject.GetComponent<DataBullet>();
takeDamage(bulletData.damage);
checkAlive(alive);
}
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}