using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChargeScript : MonoBehaviour {
	Vector3 currentMousePos; 
	Vector3 movePos;
	Vector3 startPos; 
	Vector3 nextPos;
	//Vector3 endPos;
	Transform m_parentFlame;

	public float timeToPointS;
	float currentTime;

	public float deathTimer = 10f;

	void Start(){
		GameObject[] lightFogs = GameObject.FindGameObjectsWithTag("LightFog");
		if (lightFogs.Length > 0)
		{
			lightFogs[0].GetComponent<LightFogManager>().AddLightTarget(gameObject);
		}
	}//end start

	void Update(){
		if(m_parentFlame){
			currentMousePos.z = 0; 
			if (currentTime > 0) {
				currentTime -= Time.deltaTime;
				if(currentTime<0){currentTime = 0;}
				nextPos = Vector3.Lerp (startPos, currentMousePos,(timeToPointS - currentTime)/timeToPointS);
				this.transform.position = nextPos;
			}
			if (deathTimer > 0) {
				deathTimer -= Time.deltaTime;
				if (deathTimer < 0) {
					Destroy (gameObject); 
				}
			}
		}
	}//end update

	public void SetCurrentPos(Transform parentFlame, Vector3 mycurrentPos){
		Debug.Log ("i live");
		currentTime = timeToPointS;
		currentMousePos = mycurrentPos;
		startPos = parentFlame.position;
		m_parentFlame = parentFlame;
	}//SetCurretnPos
		
	void OnDestroy(){
		Debug.Log ("reduceing count");
		m_parentFlame.GetComponent<FlameFriend_2> ().SetChargeCount();
		GameObject[] lightFogs = GameObject.FindGameObjectsWithTag("LightFog");
		if (lightFogs.Length > 0)
		{
			lightFogs[0].GetComponent<LightFogManager>().RemoveLightTarget(gameObject);
		}
	}//end on destroy
}//end class