AttackableUnit playerCharacter = GetPlayerCharacter(); Enemy enemy = GetEnemy(); if(enemy.IsValidTarget(playerCharacter)) { enemy.Attack(playerCharacter); }
AttackableUnit target = GetTarget(); NPC npc = GetNPC(); if(npc.IsValidTarget(target)) { if(npc.CanAttack(target)) { npc.Attack(target); } else { Debug.Log("Target out of range or not in line of sight."); } }Package/library: This method is most likely part of a game development library, such as Unity or Unreal Engine. It could also be part of a custom game development framework.