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

public class TransmitFromArcadia : MonoBehaviour {

    public GameObject MoneyGL, BrainGL, FoodGL, FuelGL;
    GameObject clone;

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

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

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

    public void MakeFuel()
    {
        clone = Instantiate(FuelGL, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        clone.name = "FuelGL";
        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("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt = 0;
    }

    public void DragEnd()
    {
        if (clone.name == "BitCoinGL")
        {
            if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitMoneyFromGL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
        else if (clone.name == "BrainGL")
        {
            if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitBrainFromGL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
        else if (clone.name == "FoodGL")
        {
            if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitFoodFromGL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
        else if (clone.name == "FuelGL")
        {
            if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 1)
            {
                GameObject.Find("Game Manager").GetComponent<StartingCalcs>().TransmitFuelFromGL();
                //Debug.Log("Its In!!");
                StartCoroutine(Destroyclone());
            }
            else if (GameObject.Find("BlaBlaLand").GetComponent<ZionCalculations>().DragEnt == 0)
            {
                //Debug.Log("Its Out!!");
                Destroy(clone);
            }
        }
    }


}
