using UnityEngine;

public class TrailPip : MonoBehaviour
{
	public float lifeTime = 1f;

	private float liveUntil;
	private SpriteRenderer rend;

	void Start()
    {
		rend = GetComponent<SpriteRenderer>();

		liveUntil = Time.time + lifeTime;
		rend.color = new Color(0.65f, 0.65f, 0.65f, 1.0f);
	}

    void Update()
    {
		float lifeLeft = Mathf.Max(0, liveUntil - Time.time);
		float lifePct = lifeLeft / lifeTime;

		transform.localScale = Mathf.Max(0.1f, lifePct) * Vector2.one;

		if(lifeLeft == 0)
		{
			Destroy(gameObject);
		}
	}
}
