using UnityEngine;
using System.Collections;

public class PlayerPowerUps : MonoBehaviour {

	public bool start;
	public int value;
	public string type;

	public int factor;

	private float startTime;
	private float currentTime;
	public float timeleft;
	public int initialValue;
	private bool run;

	void Awake()
	{
		start = false;
		run = false;
	}

	void Update () 
	{
		currentTime = Time.time;
		timeleft = currentTime - startTime;

		if (start) 
		{
			startTime = Time.time;
			initialValue = value;
			if(type == "Speed")
			{
				initialValue = gameObject.GetComponent<Move>().speed;
				gameObject.GetComponent<Move>().speed = initialValue + (value * factor);
			}
			else if(type == "Invisibility")
			{
				gameObject.GetComponent<MeshRenderer>().enabled = false;
			}
			else if(type == "Multiplier")
			{
				PlayerPrefs.SetInt ("Multiplier", value * factor);
			}
			else if(type == "Sanity")
			{
				initialValue = gameObject.GetComponent<Move>().sanityLevel;
				gameObject.GetComponent<Move>().sanityLevel = initialValue + (value * factor);
			}
			start = false;
			run = true;
		}

		if (run)
		{
			if ((currentTime - startTime) >= (5.0 * factor)) 
			{
				if (type == "Speed") 
				{
					gameObject.GetComponent<Move> ().speed = initialValue;
				} 
				else if (type == "Invisibility") 
				{
					gameObject.GetComponent<MeshRenderer> ().enabled = true;
				}
				else if(type == "Multiplier")
				{
					PlayerPrefs.SetInt ("Multiplier", 1);
				}
				else if (type == "Sanity") 
				{
					gameObject.GetComponent<Move> ().sanityLevel = gameObject.GetComponent<Move> ().sanityLevel - (value * factor);
				}

				run = false;
			}
		}
	}
}
