
private var player : Collider;
 
function Start()
{
	var playerObject = GameObject.FindWithTag("Player");
	if (playerObject)
		player = playerObject.collider;
	
	//if (!player)
	//	print("Could not find player object");
		
	// Default to turned off
	turnOn(false);
}

function OnTriggerEnter(other : Collider)
{
	if (other == player)
	{
		turnOn(true);
	}
}

function OnTriggerExit(other : Collider)
{
	if (other == player)
	{
		turnOn(false);
	}
}

function turnOn(on : boolean)
{
	var emitters = GetComponentsInChildren(ParticleEmitter);
	for (var emitter : ParticleEmitter in emitters)
	{
		emitter.emit = on;
	}
	
	var lights = GetComponentsInChildren(Light);
	for (var light : Light in lights)
	{
		light.enabled = on;
	}
	
	audio.mute = !on;
}