38 lines
849 B
C#
38 lines
849 B
C#
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()
|
|
{
|
|
|
|
}
|
|
}
|