Get list of enemies in range
Hello, I am creating simple Tower Defense game and I am facing problem with getting enemies in tower range. I can't figure out how to wrote tower script to check enemies in range of sphere. I want to do that without rigidbody on enemies cus if I add it to them they are bouncing and won't use navmesh correctly. Can someone tell me how I can solve it correctly? I tried with ontriggerenter/exit but it seems I am doing something wrong cus no collisions is detected.
you can make a small script and attach it to enemy, which will continuously check the distance between the tower and enemy.
like,
float dist = vector3.distance(enemy.position, tower.potion);
if the value of dist is less than certain value, tower will start attacking the enemy.
Answer by hexagonius · Oct 15, 2015 at 05:54 AM
Its fine to use sphere collider on enemy as long as they're set to trigger. with the collision code, mind the upper cases. I'd also put the detection into the tower. one call on 20 enemies is cheaper than 20 calls to 1 tower.