using UnityEngine; using System.Collections; public class NewEnemyTrigger : MonoBehaviour { NewEnemyAttack enemy; public float counter; float rate = 5f; void Start () { enemy = GetComponentInChildren(); } void Update () { } void OnTriggerStay2D(Collider2D col) { if (col.GetComponentInParent()) { counter += Time.deltaTime; if (counter > rate) { counter = 0; enemy.PlayerInRange = true; } } } void OnTriggerEnter2D(Collider2D col) { if (col.GetComponentInParent()) { enemy.PlayerInRange = true; } } void OnTriggerExit2D(Collider2D col) { if (col.GetComponentInParent()) { enemy.PlayerInRange = false; } } }