using UnityEngine;
using System.Collections;

public class TimeManager : MonoBehaviour {
	float fTimeScaleTarget = 1, fTimeToWaitFor = 0;
	public bool btimeReSpeedUp = false;
	SlowTime slowTime;
	// Use this for initialization
	void Start () {
		slowTime = GameObject.Find("TimeSlower").GetComponent<SlowTime>();
		btimeReSpeedUp = false;
	}
	
	// Update is called once per frame
	void Update () {
		if (Time.timeScale != fTimeScaleTarget)
		{
//			print(fTimeToWaitFor+"  "+fTimeScaleTarget);
			if (fTimeToWaitFor <= 0) {
				Time.timeScale = Mathf.Lerp(Time.timeScale, fTimeScaleTarget, Time.deltaTime*20);
				if (Time.timeScale <= fTimeScaleTarget*3 && slowTime.bTimeSlown == false)
				{
					Time.timeScale = fTimeScaleTarget*3;
					slowTime.bTimeSlown = true;
//					print ("PikaTime");
				} 
			}else
			{
				btimeReSpeedUp = true;
				fTimeToWaitFor -= Time.unscaledDeltaTime;
			}
		}
	}
	public void SetTimeScale (float fTimeScale) 
	{
		fTimeScaleTarget = fTimeScale;
		fTimeToWaitFor = 0;
	}
	public void SetTimeScaleInSecconds (float fTimeScale, float fSecconds) 
	{
		fTimeScaleTarget = fTimeScale;
		fTimeToWaitFor = fSecconds;
//		print(fTimeToWaitFor+"  "+fTimeScaleTarget);
	}
	public void ReturnTimeScaleToNormal () 
	{
		Time.timeScale = 1;
	}
}
