using System.Collections;
using UnityEngine;

public class Juice : MonoBehaviour
{
    public InventoryManager inventoryManager;
    [SerializeField] private BoxCollider _collider;
    
    public IEnumerator collected(float duration, float maxRotation)
    {
        _collider.enabled = false;
        float rotationStep = maxRotation / duration;
        float time = 0f;
        float currentRotation = 0f;
        Vector3 presentScale = transform.localScale;

        inventoryManager.JuiceAmount++;
        
        while (time <= duration)
        {
            var rotation = transform.rotation.eulerAngles;
            rotation.y += currentRotation;
            transform.rotation = Quaternion.Euler(rotation);
            transform.localScale = Vector3.Lerp(presentScale, Vector3.zero, currentRotation / maxRotation);
            
            yield return null;
            
            time += Time.deltaTime;
            currentRotation = Mathf.Clamp((currentRotation + rotationStep * Time.deltaTime), 0f, maxRotation);
        }
    }
}
