87 lines
2.0 KiB
C#
87 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Enemy : MonoBehaviour
|
|
{
|
|
public GameManager gameManager;
|
|
|
|
[SerializeField] private float moveSpeed;
|
|
[SerializeField] private Transform target;
|
|
public float health;
|
|
public float maxHealth;
|
|
public float damage;
|
|
public bool isBosStage2;
|
|
[SerializeField] private GameObject pastaGigi;
|
|
|
|
private void Start()
|
|
{
|
|
if (pastaGigi != null)
|
|
{
|
|
pastaGigi.SetActive(false);
|
|
}
|
|
|
|
gameManager = FindObjectOfType<GameManager>();
|
|
|
|
health = maxHealth;
|
|
|
|
gameObject.tag = "Enemy";
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
transform.position = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Bullet"))
|
|
{
|
|
GameObject bullet = other.gameObject;
|
|
bullet.gameObject.SetActive(false);
|
|
if (health >= 1)
|
|
{
|
|
health -= damage;
|
|
|
|
if (health >= 80 && isBosStage2)
|
|
{
|
|
pastaGigi.SetActive(true);
|
|
}
|
|
|
|
if (health <= 0)
|
|
{
|
|
ExecuteBosDeath();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ExecuteBosDeath();
|
|
}
|
|
}
|
|
}
|
|
|
|
void ExecuteBosDeath()
|
|
{
|
|
if (isBosStage2)
|
|
{
|
|
int currentLevel = gameManager.levelCurrentIndex;
|
|
if (currentLevel == DataManager.instance.UnlockLevel)
|
|
{
|
|
DataManager.instance.UnlockLevel = currentLevel + 1;
|
|
}
|
|
gameObject.SetActive(false);
|
|
WinScreen.Open();
|
|
DataManager.instance.Save();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Enemy Die");
|
|
QuizPopUp.Open();
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|
|
}
|