Particle system turns on when player gets close.

I need help with turning on a particle system when the player gets close to it. I also need it to turn off when the player is out of its radius. javascript is how I am writing the code. I currently don’t have a script written yet.

You will be using distance in an if conditional or use an isTrigger collider to trigger the event.

On particle systems gameObjects script

if( (player.transform.position-transform.position) <= desiredDistance )
{
    //Start emission
}

or with the trigger (This trigger is on the particle systems gameObject)

function OnTriggerEnter(other:Collider)
{
    if(other.tag == "Player")
    {
        //Start emission
    }
}
function OnTriggerExit(other:Collider)
{
    //End emission
}