public override void Execute(HealthComponent t) { self_destruct = true; Collider2D[] hit = Physics2D.OverlapCircleAll((Vector2)this.transform.position, range); foreach (Collider2D c in hit) { HealthComponent h = c.gameObject.GetComponent <HealthComponent> (); if (h != null && UnitAIBehaviour.ObjectInMask(h.gameObject, layerTarget)) { h.Damage(damage); } } HealthComponent self = this.GetComponent <HealthComponent> (); if (self != null) { self.Kill(); } else { Destroy(this.gameObject); } }
// Update is called once per frame void Update() { Collider2D[] hit = Physics2D.OverlapCircleAll((Vector2)this.transform.position, range); foreach (Collider2D c in hit) { HealthComponent h = c.gameObject.GetComponent <HealthComponent>(); if (h != null && UnitAIBehaviour.ObjectInMask(h.gameObject, targets)) { h.Damage(damage * Time.deltaTime); } } }