using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ProgressBar : MonoBehaviour {

	public Image progressImage;

	public bool isStarted = false;
	public float MaxTime = 5;
	public float ActiveTime = 5f;

	public RectTransform waterTransform;

	void Start()
	{
		ActiveTime = MaxTime;
	}

	public void Update()
	{
		if (ActiveTime > 0 && isStarted) {
			ActiveTime -= Time.deltaTime;
		}

		var percent = ActiveTime / MaxTime;
		progressImage.fillAmount = Mathf.Lerp (0, 1, percent);
		waterTransform.anchorMin = new Vector2(Mathf.Lerp (0, 1, percent) - 0.02f, 0);
		waterTransform.anchorMax = new Vector2(Mathf.Lerp (0, 1, percent), 1);
	}

	public void ResetProgress()
	{
		ActiveTime = MaxTime;
		isStarted = false;
	}

	public void StartProgress()
	{
		isStarted = true;
	}

	public void StopProgress()
	{
		isStarted = false;
	}
}
