void Update() { int layerMask = (~(1 << LayerMask.NameToLayer("Ground"))); Collider[] hitColliders = Physics.OverlapSphere(transform.position, attackRange, layerMask); for (int i = 0; i < hitColliders.Length; i++) { BaseObject collidingObject = GetBaseObject(hitColliders[i]); if (collidingObject != null && attackRule.canAttack(attachedBaseObj, collidingObject)) { NotifyListeners(collidingObject); return; } } }
public override void OnEnemyClick(BaseObject target) { //We need some kind of behaviour pattern here. Example: What happends if selected -> press on own/enemy building? if (target != null) { if (attackRule.canAttack(GetPlayer(), target)) { //attack //Walk to the enemy position - our shooting range. The RangedEnemyDetector will then handle the attacking. } else { //show feedback } } }