using UnityEngine;
using System.Collections;

public class KeyPickupEffect : MonoBehaviour {
	
	static private KeyPickupEffect myInstance;
	
	static public void Summon(Vector3 position) {
		myInstance.transform.position = position + Vector3.down * 0.5f;
		myInstance.StartCoroutine(myInstance.PlayAndStop(myInstance.particleSystem.startLifetime));
	}
	
	// Use this for initialization
	private void Awake() {
		if (myInstance != null) GameObject.Destroy(myInstance);
		myInstance = this;
		particleSystem.Stop();
		audio.Stop();
	}
	
	private IEnumerator PlayAndStop(float delay) {
		particleSystem.Play();
		audio.Play();
		yield return new WaitForSeconds(delay);
		particleSystem.Stop();
		audio.Stop();
	}
}
