using UnityEngine;

public class SimpleSpeedLine : MonoBehaviour
{
    private LineRenderer LR;
    public float fadespeed = 1f;
    private float alpha = 1f;
    public Vector3 playerpos1;
    public Vector3 playerpos2;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        LR = GetComponent<LineRenderer>();
        LR.positionCount = 2;
        LR.SetPosition(1, playerpos1);
        LR.SetPosition(0, playerpos2);
    }

    void Update()
    {
        if(alpha > 0)
        {
            alpha -= Time.deltaTime * fadespeed;
            Gradient gradient = new Gradient();
            gradient.SetKeys(LR.colorGradient.colorKeys, new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0f), });
            LR.colorGradient = gradient;
        }
        else
        {
            Destroy(gameObject);
        }
    }
}
