using UnityEngine;
using System.Collections;

public class FishTank : MonoBehaviour {

	public AudioClip splash;
	public int breakingPoint;
	public GameObject spoutingWater;
	public GameObject sparks;
	public GameObject door1;
	public GameObject door2;
	public Transform pos1;
	public Transform pos2;
	public Transform water;
	private States states;

	// Use this for initialization
	void Start () {
		states = GameObject.Find("Player").GetComponent<States>();
	}
	
	void Update ()
	{
		/*Vector3 temp = water.position;
		temp.y = pos1.position.y + (pos2.position.y - pos1.position.y) * (states.tankWater / breakingPoint);
		water.position = temp;*/
		Debug.Log (states.tankWater / breakingPoint);
		float one = states.tankWater;
		float two = breakingPoint;
		water.position = Vector3.Lerp (pos1.position, pos2.position, (one / two));
	}
	
	void Use ()
	{
		if (states.water > 0)
		{
			AudioSource.PlayClipAtPoint(splash, transform.position);
			states.tankWater++;
			states.water--;
		}
		if (states.tankWater >= breakingPoint)
		{
			spoutingWater.SetActive(true);
			//audio.Play();
		}
	}
	
	void Sleep ()
	{
		if (states.tankWater >= breakingPoint)
		{
			sparks.SetActive (true);
			door1.SetActive (false);
			door2.SetActive (true);
			GameObject.Find("FaderC").audio.Pause ();
		}
	}
}
