using UnityEngine; using System.Collections; public class Boss1AttackScript : MonoBehaviour { GameObject player; public float Damage = 20; float timer = .5f; float counter; bool playerInRange; bool active; void Start() { counter = 0; player = GameObject.FindGameObjectWithTag("Player"); } void Update() { if (active) { counter += Time.deltaTime; if (counter >= timer && playerInRange) { counter = 0f; player.GetComponent().TakeDamage(Damage); } } } void OnTriggerEnter2D(Collider2D other) { var player = other.gameObject.GetComponentInParent(); if (player != null) { playerInRange = true; } } void OnTriggerExit2D(Collider2D other) { var player = other.gameObject.GetComponentInParent(); if (player != null) { playerInRange = false; } } public void EnableBoss1Attack() { active = true; } public void DisableBoss1Attack() { active = false; } }