modifing enemies target inside a radius

basically i am trying to set my players transform as the target of the enemies that pass by him, i have tried a couple of method but the only one that look like i am on the right track is this.

code :

var range : float = 5.0;

function Update {
var playerPosition = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (playerPosition, range);
		for (var i = 0; i < colliders.Length; i++) {
			colliders*.GetComponent(enemies).target = transform;*
  •  }* 

i believe that the line colliders*.GetComponent(enemies).target = transform; is not the way to go. so how can i manage to set my transform as the target of the enemies inside the given radius?*

Well you should use maths instead of physics for this. On each enemy you just check how far away the player is.

  1. Get a reference to the player in the enemy script Start function (use FindObjectsWithTag or perhaps a Singleton script).
  2. On the enemy’s Update check the distance to the player - use the square distance for performance


   static var instance : Transform;

   function Awake() {
         instance = transform;

var radius : float = 20;

   function Update() {
        if((Player.instance.position - transform.position).sqrMagnitude < (radius * radius)) {
             //Player is in range