using UnityEngine;
using System.Collections;

public class Lever : MonoBehaviour 
{
	private Animator animator;

	public AudioClip leverSound;

	public GameObject[] targets;

	private void Awake()
	{
		animator = GetComponent<Animator>();
	}

	private void OnTriggerEnter2D(Collider2D other)
	{
		if(animator.GetBool("On")) return;


		if(other.CompareTag("Player"))
		{
			animator.SetBool("On", true);

			Destroy(GetComponentInChildren<ParticleSystem>());

			GetComponent<AudioSource>().PlayOneShot(leverSound);

			foreach(var target in targets)
			{
				target.BroadcastMessage("OnLeverChange", true);
			}

			enabled = false;
		}
	}
}
;