﻿using UnityEngine;
using System.Collections;

namespace Nostalgia.Example
{
	[AddComponentMenu("Nostalgia/Example/BlinkLight"), RequireComponent(typeof(Light))]
	public sealed class BlinkLight : MonoBehaviour
	{
		public float duration = 1.0f;
		public float _BlinkScale = 0.8f;
		public float beginTime = 0.0f;
		Light _Light;
		float _Range;
		float _BeginTime;

		void Awake()
		{
			_Light = GetComponent<Light>();
			_Range = _Light.range;
			_BeginTime = Time.time;
		}

		// Update is called once per frame
		void Update()
		{
			if (duration > 0.0f)
			{
				float t = (Time.time - _BeginTime + beginTime) / duration;
				t = (Mathf.Sin(t) + 1.0f) / 2.0f;
				_Light.range = Mathf.Lerp(_Range, _Range * _BlinkScale, t);
			}
		}
	}

}
