using UnityEngine;
using System.Collections;

public class TieScript : MonoBehaviour {

    bool canTie;
    Item thing = new Item();

	// Use this for initialization
	void Start ()
    {
        canTie = false;
        //thing = null;
	}

    void OnTriggerEnter(Collider other)
    {
        if (other.GetComponent<Item>() != null)
        {
            canTie = true;
            thing = other.GetComponent<Item>();
        }
    }

    void OnTriggerExit(Collider other)
    {
        canTie = false;
        thing = null;
    }

    void TieObject(Item item)
    {
        if (item.GetIsTied() == false)
        {
            Debug.Log("Use pressed");
            item.SetIsTied(true);
        }
    }

    // Update is called once per frame
    void Update ()
    {
        if (Input.GetButtonDown("Use"))
        {
            if (canTie == true)
            {
                //TieObject(other.gameObject.GetComponent<Item>());
                if (thing.GetComponent<Item>() != null)
                {
                    TieObject(thing.gameObject.GetComponent<Item>());
                }
                //Remove current item and replace it with tied model
            }
        }
    }
}
