using UnityEngine;
using System.Collections;

public class LaserHUD : MonoBehaviour {

	private bool hudEnabled;
	private float countdown;
	private float startTime;
	private float cScale;

	void Awake(){
		transform.parent.renderer.enabled = false;
		renderer.enabled = false;
		hudEnabled = false;
		countdown = 0.0f;
		cScale = 1.0f;
	}
	
	void FixedUpdate () {
		if(hudEnabled){
			cScale = Mathf.Lerp(1.0f, 0.0f, (Time.time - startTime) / Constants.LASER_TIME_LIMIT);
			transform.localScale = new Vector3(cScale, cScale, cScale);
			if(countdown < Constants.LASER_TIME_LIMIT){
				countdown += Time.deltaTime;
			} else {
				transform.parent.renderer.enabled = false;
				renderer.enabled = false;
				hudEnabled = false;
				countdown = 0.0f;
				cScale = 1.0f;
			}
		}
	}
	
	public void Activate(){
		hudEnabled = true;
		transform.parent.renderer.enabled = true;
		renderer.enabled = true;
		startTime = Time.time;
	}
}
