Object moves toward another object when close

Hi all,

I currently have objects following my player with script that works, however I want the objects to only become active when the player draws near to them.

public class EnemyLook : MonoBehaviour {

	public Transform target;
	public GameObject player;
        public float speed;

    
	void Update() {
        
	float step = speed * Time.deltaTime;
       transform.position = Vector3.MoveTowards(transform.position, target.position, step);
		
		transform.LookAt(target);
		

 
	}
}

I wouldn’t mind using raycast to do so, though I have no experience using rays and would greatly appreciate any help.

Thanks

Check the object distance about the player and the object, with: Vector3.Distance

Then apply your script to calculate how many meters you want to active then.

Put a big Sphere Collider on your player and mark it as trigger

Then you just has to do this - 

void OnTriggerStay(Collider col) {
 if(col.collider.name == "Player"){
    float step = speed * Time.deltaTime;
       transform.position = Vector3.MoveTowards(transform.position, target.position, step);
 
       transform.LookAt(target);
 }
 
 
    }