using System.Collections;
using UnityEngine;

public class Present : MonoBehaviour
{
    public InventoryManager inventoryManager;
    
    public IEnumerator collected(float duration, float maxRotation)
    {
        float rotationStep = maxRotation / duration;
        float time = 0f;
        float currentRotation = 0f;
        Vector3 presentScale = transform.localScale;

        inventoryManager.PresentAmount++;
        
        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);
        }
    }
}
