summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Boss1/Boss1FireScript.cs
blob: 35978b31e1cb58f1da55e3c98500e80396f2171f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using UnityEngine;
using System.Collections;

public class Boss1FireScript : MonoBehaviour {
    public float FireRate = 1.5f;
    float fireCounter;
    bool PlayerInRange = false;
    public GameObject Bullet;
    public float BulletSpeed = 20;
    bool active;

    AudioSource EnemyFireAudio;


    void Start()
    {
        EnemyFireAudio = GameObject.FindGameObjectWithTag("EnemyFireAudio").GetComponent<AudioSource>();
    }

    void Update()
    {
        if (active)
        {
            fireCounter += Time.deltaTime;
            if (fireCounter >= FireRate && PlayerInRange)
            {
                fireCounter = 0;
                EnemyFireAudio.Play();
                Fire();

            }
        }        
    }

    void Fire()
    {
        //var Bullet1 = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity) as GameObject;
        //Bullet1.GetComponent<Rigidbody2D>().velocity = Vector2.up * BulletSpeed;
        //var Bullet2 = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity) as GameObject;
        //Bullet2.GetComponent<Rigidbody2D>().velocity = Vector2.right * BulletSpeed;
        //var Bullet3 = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity) as GameObject;
        //Bullet3.GetComponent<Rigidbody2D>().velocity = Vector2.down * BulletSpeed;
        //var Bullet4 = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity) as GameObject;
        //Bullet4.GetComponent<Rigidbody2D>().velocity = Vector2.left * BulletSpeed;
        //Destroy(Bullet1, 1.5f);
        //Destroy(Bullet2, 1.5f);
        //Destroy(Bullet3, 1.5f);
        //Destroy(Bullet4, 1.5f);

        for (int i = 0; i < 24; i++)
        {
            var b = Instantiate(Bullet, gameObject.transform.position, Quaternion.identity) as GameObject;
            b.GetComponent<Rigidbody2D>().velocity = new Vector2(
                (Mathf.Cos(i*Mathf.PI*.1f)) * 20,
                (Mathf.Sin(i*Mathf.PI*.1f)) * 20 
                );
            Destroy(b, 2.5f);
        }
    }
   

    void OnTriggerEnter2D(Collider2D other)
    {
        var player = other.gameObject.GetComponentInParent<PlayerHealthScript>();
        if (player != null)
        {
            PlayerInRange = true;
        }
    }

    void OnTriggerExit2D(Collider2D other)
    {
        var player = other.gameObject.GetComponentInParent<PlayerHealthScript>();
        if (player != null)
        {
            PlayerInRange = false;
        }
    }

    public void EnableBoss1Fire()
    {
        active = true;
    }
    public void DisableBoss1Fire()
    {
        active = false;
    }

}