Example #1
0
 // we need a function to check if an entity can attack another.
 // => overwrite to add more cases like 'monsters can only attack players'
 //    or 'player can attack pets but not own pet' etc.
 // => raycast NavMesh to prevent attacks through walls, while allowing
 //    attacks through steep hills etc. (unlike Physics.Raycast). this is
 //    very important to prevent exploits where someone might try to attack a
 //    boss monster through a dungeon wall, etc.
 public virtual bool CanAttack(Entity entity)
 {
     return(health > 0 &&
            entity.health > 0 &&
            entity != this &&
            !inSafeZone && !entity.inSafeZone &&
            !NavMesh2D.Raycast(transform.position, entity.transform.position, out NavMeshHit2D hit, NavMesh2D.AllAreas));;
 }