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

public class Heartbeater : MonoBehaviour {

	private Animator anim;
	public float beatSpeed;
	private GameObject GameControllerObject;
	private GameController gc;
	public Color lowColor, highColor;
	public float lowestSpeed, highestSpeed;

	// Use this for initialization
	void Start () {
		GameControllerObject = GameObject.FindGameObjectWithTag("GameController");
		gc = GameControllerObject.GetComponent<GameController>();
	}

	// Update is called once per frame
	void Update () {
		float diff = highestSpeed - lowestSpeed;
		GetComponent<Image> ().color = Color.Lerp (lowColor, highColor, gc.panicValue);
		beatSpeed = gc.panicValue * diff + lowestSpeed;
		anim = gameObject.GetComponent<Animator>();
		anim.speed = beatSpeed;
	}
}
