60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Boss : MonoBehaviour
|
|
{
|
|
public float Health, attackDelay;
|
|
float f;
|
|
public Transform Missile, Firepoint;
|
|
public int attack;
|
|
Animator anim;
|
|
public GameObject wall;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
anim = GetComponent<Animator>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
f += Time.deltaTime;
|
|
if (f >= attackDelay && attack == 1)
|
|
{
|
|
f = 0;
|
|
anim.SetTrigger("newAttack");
|
|
attack = 0;
|
|
shootMissiles();
|
|
}
|
|
if (attack == 0 && GameObject.FindGameObjectsWithTag("Missile").Length == 0)
|
|
{
|
|
anim.SetTrigger("newAttack");
|
|
attack = 1;
|
|
f = 0;
|
|
}
|
|
if (Health <= 0)
|
|
{
|
|
Destroy(gameObject);
|
|
Destroy(wall);
|
|
}
|
|
}
|
|
public void shootMissiles()
|
|
{
|
|
Transform bullet = Instantiate(Missile, Firepoint.position, Firepoint.rotation);
|
|
}
|
|
private void OnCollisionEnter2D(Collision2D collision)
|
|
{
|
|
if(collision.gameObject.tag == "Bullet"){
|
|
Health -= 1;
|
|
}
|
|
|
|
if (collision.transform.tag == "Player")
|
|
{
|
|
collision.transform.GetComponent<PlayerStats>().Die();
|
|
this.enabled = false;
|
|
}
|
|
|
|
}
|
|
}
|