using System.Collections;
using UnityEngine;

public class fadeouteffect : MonoBehaviour
{
    float fadeOutDuration = 0.5f; // Change this value to adjust the fade-out duration
    float initialOpacity = 1.0f; // Set the initial opacity to 1 for full opacity
    float currentAlpha;
    float speed;
    Color c;
    void OnEnable()
    {
        speed = initialOpacity / fadeOutDuration;
        currentAlpha = initialOpacity;
        StartCoroutine(FadeOut());
    }

    IEnumerator FadeOut()
    {

        while (currentAlpha > 0)
        {
            currentAlpha -= speed * Time.deltaTime;

            c = new Color(1, 1, 1, currentAlpha);
            gameObject.GetComponent<LineRenderer>().startColor = c;
            gameObject.GetComponent<LineRenderer>().endColor = c;
            yield return null;
        }


        gameObject.SetActive(false);
    }

}
