using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;

public class InvisibleSoulCollector : MonoBehaviour
{
    public int soulNumbers;
    public SoulFollowEffect soulFollowEffect;
    private void OnTriggerEnter(Collider other)
    {
        Soul soul = other.GetComponentInParent<Soul>();
        if (soul)
        {
            BeCollect(soul);
        }
    }
    public async void BeCollect(Soul soul)
    {
        soulNumbers++;
        soul.rb.isKinematic = true;
        soul.collected = true;
        soul.tweenPos.from = transform;
        soul.tweenPos.to = transform;
        soul.tweenPos.duration = (soul.tweenPos.from.position - soul.tweenPos.to.position).magnitude
            / soul.flySpeed;
        soul.tweenPos.ResetToBeginning();
        soul.tweenPos.PlayForward();
        await Task.Delay((int)(soul.tweenPos.duration * 1000));
        SoulInMap.souls.Remove(soul);
        soul.gameObject.SetActive(false);
        soulFollowEffect.ShowSouls(soulNumbers);
    }
}
