示例#1
0
    /// <summary>
    /// Put item into this cell.
    /// </summary>
    /// <param name="item">Item.</param>
    private void PlaceItem(DragAndDropItem item)
    {
        if (item != null)
        {
            DestroyItem();                                                              // Remove current item from this cell
            myDadItem = null;
            DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>();
            if (cell != null)
            {
                if (cell.unlimitedSource == true)
                {
                    string itemName = item.name;
                    item      = Instantiate(item);                                              // Clone item from source cell
                    item.name = itemName;
                }
            }
            item.transform.SetParent(transform, false);
            item.transform.localPosition = Vector3.zero;
            item.MakeRaycast(true);

            myDadItem = item;
            myDadItem.GetComponent <CanvasGroup>().alpha = 0.5f; //Hace que el item no sea visible cuando llega a la boca

            GameObject       canvas    = gameObject.transform.parent.gameObject;
            AtributosMascota atributos = canvas.transform.Find("MANAGER CANVAS").GetComponent <AtributosMascota>();

            Animator anim = LINCE.GetComponent <Animator>();
            anim.SetInteger("estaComiendo", 2);

            GestionComida gestorComida = canvas.transform.Find("Plato").GetComponent <GestionComida>();
            GameObject    comida       = canvas.transform.Find("Plato").gameObject.transform.Find("Comida").gameObject;
            TMP_Text      porcentaje   = canvas.transform.Find("Plato").gameObject.transform.Find("Porcentaje").gameObject.GetComponent <TMP_Text>();
            comida.GetComponent <DragAndDropItem>().enabled = false;;
            atributos.subirHambre(int.Parse(porcentaje.text));
            gestorComida.EliminarItem(item.gameObject);
            Image imagen = comida.GetComponent <Image>();
            imagen.color = new Color(imagen.color.r, imagen.color.g, imagen.color.b, 0.5f); //Item del plato

            StartCoroutine(ExecuteAfterTime(3));
        }

        UpdateBackgroundState();
    }