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

public enum PickupType
{
    Weapon,
    Ammo
}

public class Pickup : MonoBehaviour
{
    [SerializeField]
    private GameObject _attachPoint;

    [SerializeField]
    public GameObject pickupPrefab;

    [SerializeField]
    public PickupType pickupType = PickupType.Weapon;

    private Vector3 _initPos;

    void Start()
    {
        _initPos = _attachPoint.transform.position;

        GameObject pickup = Instantiate(
            pickupPrefab,
            _attachPoint.transform
        );
        Destroy(pickup.GetComponent<Rigidbody>());
        Destroy(pickup.GetComponent<Collider>());
        if (pickupType == PickupType.Ammo)
        {
            _attachPoint.transform.localScale *= 4;
            pickup.GetComponent<Projectile>().keepAlive = true;
        }
    }

    void Update()
    {
        _attachPoint.transform.Rotate(Vector3.up, 2f, Space.World);
        _attachPoint.transform.position = new Vector3(
            transform.position.x,
            _initPos.y + Mathf.Sin(Time.timeSinceLevelLoad) * 0.25f,
            transform.position.z
        );
    }
}
