How to make it so enemies only move towards the player when the player is colliding with an object (89008)

It’s more so when you touch an object with the tag “light” then any object with the tag “enemy” will become active and move towards the player.

#pragma strict

function Start () 
{
	GetComponent("ENEMY").active = false;
}

function Update () 
{

}
function OnCollisionEnter (collision : Collision)
{
	while(collision.gameObject.tag == "light")
    {
    	GetComponent("ENEMY").active = true; 
    }
    GetComponent("ENEMY").active = false;
}

First, you don’t want to use a ‘while’ statement there. That will loop forever if the object is a ‘light’ object. Replace that ‘while’ with ‘if’ and get rid of the line ‘GetComponent(“ENEMY”).active = false;’.

Second, you will need to have an OnCollisionExit function that disables the Enemies if you’re leaving the light object. It will be the same as your OnCollisionEnter function, but you will set the active state to false.