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

public class PulseLife : MonoBehaviour {
	public Material mat;
	public Color color,newColor;
	public float smZ,mZ,lZ;
	public float duration;
	public bool small,medium,large;

	// Use this for initialization
	void Start () 
	{
		smZ = 0.65f;
		mZ = 0.95f;
		lZ = 1.05f;
		if(small)
		{
			duration = smZ;
		}
		if(medium)
		{
			duration = mZ;
		}
		if(large)
		{
			duration = lZ;
		}
		mat = GetComponentInChildren<Renderer>().material;
		color = GetComponentInChildren<Renderer>().material.color;
		Invoke("Delete", duration-0.25f);
	}
	void Update()
	{
	
		newColor = mat.color;
		newColor.a -= Time.deltaTime * duration;		
		newColor.r -= Time.deltaTime * duration;		
		newColor.b -= Time.deltaTime * duration;		
		newColor.g -= Time.deltaTime * duration;		
		GetComponentInChildren<Renderer>().material.SetColor("_Color", newColor);

	}
	
	void Delete()
	{
		Destroy(this.gameObject);
	}
}
