using System.Collections; using System.Collections.Generic; using UnityEngine; public class DamageDealingPlant : MonoBehaviour { public bool inRange = false; public float timerDmg = 0f; public float waitTime = 1.0f; public bool firstAttack = false; public float baseAttack = 1.0f; public bool isPanelEnabled = true; public GameObject other; void Start() { other = GameObject.FindWithTag("Player"); } void OnTriggerEnter2D(Collider2D collision) { ///For attacking player if (collision.tag == "PlayerHitbox") { inRange = true; firstAttack = false; } } void OnTriggerStay2D(Collider2D collision) { ///For attacking player if (collision.tag == "PlayerHitbox") { inRange = true; } } void OnTriggerExit2D(Collider2D collision) { ///For attacking player inRange = false; timerDmg = 0f; } // Update is called once per frame void Update() { if (inRange == true) { if (firstAttack == false) { if (timerDmg >= 0.15f) { firstAttack = true; other.GetComponent().TakeDamage(baseAttack, isPanelEnabled); timerDmg = 0f; } } if (timerDmg >= waitTime) { timerDmg = 0f; other.GetComponent().TakeDamage(baseAttack, isPanelEnabled); } timerDmg += Time.deltaTime; } } }