summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Enemy2/NewEnemyTrigger.cs
blob: 210204923f228417468f5773d1518835257a7957 (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
using UnityEngine;
using System.Collections;

public class NewEnemyTrigger : MonoBehaviour {

    NewEnemyAttack enemy;
    public float counter;
    float rate = 5f;

	void Start () {
        enemy = GetComponentInChildren<NewEnemyAttack>();
	}
	
	
	void Update () {
	
	}

    void OnTriggerStay2D(Collider2D col)
    {
        if (col.GetComponentInParent<PlayerHealthScript>())
        {
            counter += Time.deltaTime;
            if (counter > rate)
            {
                counter = 0;
                enemy.PlayerInRange = true;
            }
                
        }
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.GetComponentInParent<PlayerHealthScript>())
        {
            enemy.PlayerInRange = true;
        }
    }

    void OnTriggerExit2D(Collider2D col)
    {
        if (col.GetComponentInParent<PlayerHealthScript>())
        {
            enemy.PlayerInRange = false;
        }
    }
}