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

public class TransmitFromZion : MonoBehaviour {

    public GameObject MoneyBBL, BrainBBL, FoodBBL, FuelBBL;
    GameObject clone;

    public void MakeMoney()
    {
        clone = Instantiate(MoneyBBL, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        clone.name = "BitCoin";
        clone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
    }

    public void MakeBrain()
    {
        clone = Instantiate(BrainBBL, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        clone.name = "Brain";
        clone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
    }

    public void MakeFood()
    {
        clone = Instantiate(FoodBBL, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        clone.name = "Food";
        clone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
    }

    public void MakeFuel()
    {
        clone = Instantiate(FuelBBL, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        clone.name = "Fuel";
        clone.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
    }

    public void Dragging()
    {
        clone.transform.position = Input.mousePosition;
    }

    IEnumerator Destroyclone()
    {
        yield return new WaitForSeconds(0.1f);
        Destroy(clone);
        GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt = 0;
    }

    public void DragEnd()
    {
        if (clone.name == "BitCoin")
        {
            if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitMoneyFromBBL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
        else if (clone.name == "Brain")
        {
            if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitBrainFromBBL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
        else if (clone.name == "Food")
        {
            if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitFoodFromBBL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
        else if (clone.name == "Fuel")
        {
            if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitFuelFromBBL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("GibberishLand").GetComponent<ArcadiaCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
    }


}
