using UnityEngine;
using System.Collections;

public class s_PlatformLife : s_Platform
{
	
	public int health;
	public Texture2D hp2;
	public Texture2D hp1;
	public Texture2D hp0;
	
	void Start()
	{
		if (health == 2)
			renderer.material.mainTexture = hp2;
		else
			renderer.material.mainTexture = hp1;
	}
	
	override public void Hit()
	{	
		--health;
		
		//Change texture if you have extra life
		if (health == 1)
			renderer.material.mainTexture = hp1;
		
		if (health <= 0)
			StartCoroutine(DisableSelf());
	}
	
	IEnumerator DisableSelf()
	{	
		Vector3 pos = transform.position;
			
		renderer.material.mainTexture = hp0;
	    transform.Translate(Vector3.up * 10000);
		yield return new WaitForSeconds(0.03f);
		transform.position = pos;
		AudioManager.PlaySound(AudioManager.lily, 0.5f);
	}
	
	public IEnumerator EnableSelf()
	{	
		Vector3 pos = transform.position;
		
	    transform.Translate(Vector3.up * 10000);
		yield return new WaitForSeconds(0.03f);
		transform.position = pos;
	}
}
