using UnityEngine;
using System.Collections;

/// <summary>
/// Creating instance of particles from code with no effort
/// </summary>
public class Efects : MonoBehaviour
{
	/// <summary>
	/// Singleton
	/// </summary>
	//public static Efects Instance;

	public ParticleSystem smokeEffect;

	void Awake()
	{
		// Register the singleton
		/*if (Instance != null)
		{
			Debug.Log("Multiple instances of SpecialEffectsHelper!");
		}

		Instance = this;*/
	}

	/// <summary>
	/// Create an explosion at the given location
	/// </summary>
	/// <param name="position"></param>
	public void Explosion(Vector3 position)
	{
		// Smoke on the water
		instantiate(smokeEffect, position);
		Debug.Log ("Entra");
	}

	/// <summary>
	/// Instantiate a Particle system from prefab
	/// </summary>
	/// <param name="prefab"></param>
	/// <returns></returns>
	private ParticleSystem instantiate(ParticleSystem prefab, Vector3 position)
	{
		ParticleSystem newParticleSystem = Instantiate(
			prefab,
			position,
			Quaternion.identity
		) as ParticleSystem;

		newParticleSystem.Play ();

		// Make sure it will be destroyed
		Destroy(
			newParticleSystem.gameObject,
			newParticleSystem.startLifetime
		);

		return newParticleSystem;
	}
}