what would be the ideal solution to having a tower with a range of tiles. for example, the tower is placed on [0,0] and if there are enemies on tile [0,1] or [0,2] the tower will attack one of these enemies. I could give enemies a boxcollider and the towers custom boxcolliders with a rigidbody however I feel like there should be a better solution without the need of rigidbodies for the enemies or tower since they are heavy on performance… anyone any ideas for what the best approach would be?
If it’s turn based, I would check every time an enemy moves to see if the new position is on said tiles. If it is a question of frame by frame monitoring, than I would say collisions or distance checks are your best bet. The option for distance:
if(Vector3.Distance(tower.transform.position, enemy.transform.position) <= tileSpread){
//enemy close
}
//or a bit faster with square magnitude
if((tower.transform.position - enemy.transform.position).sqrMagnitude <= tileSpread){
//enemy close
}