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

public class Pickable : MonoBehaviour
{
    [SerializeField]
    private Transform HandPosition;

    [SerializeField]
    protected Transform player;

    [SerializeField]
    protected Transform Camera;

    [SerializeField]
    private float force;
    private Rigidbody rb;

    public virtual void Start()
    {
        rb = gameObject.GetComponent<Rigidbody>();
    }

    public virtual void PickUp()
    {
        CharacterControl.handsFull = true;
        rb.isKinematic = true;
        gameObject.GetComponent<BoxCollider>().isTrigger = true;
        transform.SetParent(HandPosition);
        transform.localRotation = Quaternion.Euler(Vector3.zero);
        transform.localPosition = Vector3.zero;
        transform.localScale = Vector3.one;

        Debug.Log("Picked up");
    }

    public virtual void Drop()
    {
        CharacterControl.handsFull = false;
        rb.isKinematic = false;
        gameObject.GetComponent<BoxCollider>().isTrigger = false;
        transform.SetParent(null);
        rb.velocity = player.GetComponent<Rigidbody>().velocity;
        rb.AddForce(Camera.forward * force, ForceMode.Impulse);
        float random = Random.Range(-1f, 1f);
        rb.AddTorque(new Vector3(random, random, random) * 10);
    }
}
