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

public class NoteParticleScript : MonoBehaviour
{
    public Vector3 destination;
    public float timing;
    SpriteRenderer sprite;

    Vector3 veloc = Vector3.zero;

    // Start is called before the first frame update
    void Start()
    {
        sprite = GetComponent<SpriteRenderer>();
        StartCoroutine(GoToDestination());
        Invoke("AutoDestroy", timing+0.5f);
    }

    IEnumerator GoToDestination()
    {
        while (transform.position.x < destination.x)
        {
          Color currCol = sprite.color; currCol.a -= Time.deltaTime; sprite.color = currCol;
          transform.position = Vector3.SmoothDamp(transform.position, destination, ref veloc, timing);
          yield return null;
        }
    }

    void AutoDestroy()
    {
       Destroy(gameObject);
    }

} // Fin du script

