using UnityEngine;
using System.Collections;

public class CarryableObject : MonoBehaviour, IInteractable
{
    private GameObject _carrier;

    public bool Interact(object sender)
    {
        if (_carrier != null)
        {
            transform.parent = null;
            _carrier = null;
            rigidbody.detectCollisions = true;
            rigidbody.useGravity = true;
        }
        else
        {
            GameObject carrier = (GameObject)sender;
            rigidbody.detectCollisions = false;
            rigidbody.useGravity = false;
            transform.parent = carrier.transform;
            transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y + carrier.transform.localScale.y * .5f, transform.localPosition.z);
            _carrier = carrier;
        }

        return true;
    }

    public bool IsActivatableOnKey
    {
        get { return true; }
    }


    public bool IsHandheld
    {
        get { return true; }
    }
}
