Beispiel #1
0
    void Update()
    {
        switch (treeState)
        {
        case "NeedWater":
            if (leavesWithApples.activeSelf)
            {
                leavesWithApples.SetActive(false);     //Desactivo sprite arbol con manzanas.
                leaves.GetComponent <SpriteRenderer>().enabled = true;
            }

            if (!treeLights.isStopped)
            {
                treeLights.Stop();                           //Desactivo destellos
            }
            if (manager.getSceneState() != "Placing" && !alertIcon.activeSelf && GetComponent <MovableObject>().objectState != "Selected" ||
                manager.getSceneState() != "Placing" && alertIcon.GetComponent <SpriteRenderer>().sprite != waterAlertSprite)
            {
                //Activo icono alerta y establezco el sprite de alerta para riego.
                alertIcon.GetComponent <SpriteRenderer>().sprite = waterAlertSprite;
                alertIcon.SetActive(true);
            }
            if (manager.getSceneState() == "Placing" || GetComponent <MovableObject>().objectState == "Selected")
            {
                alertIcon.SetActive(false);
            }

            break;


        case "WaitingApples":

            if (treeLights.isStopped)
            {
                treeLights.Play();                           //Activo destellos.
            }
            if (leavesWithApples.activeSelf)
            {
                leavesWithApples.SetActive(false);      //Desactivo sprite arbol con manzanas.
                leaves.GetComponent <SpriteRenderer>().enabled = true;
            }

            if (alertIcon.activeSelf)
            {
                alertIcon.SetActive(false);                          //Oculto icono de alerta.
            }
            timeToCollect += Time.deltaTime;
            Debug.Log(timeToCollect);
            if (timeToCollect >= waitingSeconds)
            {
                timeToCollect = -1;

                anim.SetBool("ApplesON", true); //animacion aparicion manzanas.

                treeState = "Collectable";      //Cuando el contador alcanza el tiempo de espera cambio a estado 'Collectable'.

                manager.SaveGame();             //Guardado estado del juego automatico.
            }

            break;


        case "Collectable":

            if (treeLights.isStopped)
            {
                treeLights.Play();                           //Activo destellos.
            }
            if (anim.GetBool("ApplesON"))
            {
                timer += Time.deltaTime;
                if (timer >= 1f)
                {
                    leavesWithApples.SetActive(true);    //activo sprite arbol con manzanas.

                    anim.SetBool("ApplesON", false);     //fin animacion aparicion manzanas
                    timer = 0f;
                    //leaves.GetComponent<SpriteRenderer>().sprite = spriteWithApples; //cambio a sprite arbol con manzanas.
                }
            }
            else if (!leavesWithApples.activeSelf)
            {
                //activa sprite arbol con manzanas en casos en los que no ocurre animacion de aparicion de manzanas (carga de escenario guardado).
                leavesWithApples.SetActive(true);
                leaves.GetComponent <SpriteRenderer>().enabled = false;
            }

            if (manager.getSceneState() != "Placing" && !alertIcon.activeSelf && GetComponent <MovableObject>().objectState != "Selected" ||
                manager.getSceneState() != "Placing" && alertIcon.GetComponent <SpriteRenderer>().sprite != appleAlertSprite)
            {
                //Activo icono alerta y establezco el sprite de alerta para manzanas.
                alertIcon.GetComponent <SpriteRenderer>().sprite = appleAlertSprite;
                alertIcon.SetActive(true);
            }

            if (manager.getSceneState() == "Placing" || GetComponent <MovableObject>().objectState == "Selected")
            {
                alertIcon.SetActive(false);
            }
            break;
        }

        /*
         *
         * if (!withApples)
         * {
         *  if(leavesWithApples.activeSelf)leavesWithApples.SetActive(false); //Desactivo sprite arbol con manzanas.
         *  timeToCollect += Time.deltaTime;
         *  Debug.Log(timeToCollect);
         *  if (timeToCollect >= 20f)
         *  {
         *      withApples = true;
         *      timeToCollect = -1;
         *
         *      anim.SetBool("ApplesON", true); //animacion aparicion manzanas.
         *  }
         * }
         * else {
         *  if (anim.GetBool("ApplesON"))
         *  {
         *      timer += Time.deltaTime;
         *      if (timer >= 1f)
         *      {
         *          leavesWithApples.SetActive(true); //activo sprite arbol con manzanas.
         *          anim.SetBool("ApplesON", false); //fin animacion aparicion manzanas
         *          timer = 0f;
         *          //leaves.GetComponent<SpriteRenderer>().sprite = spriteWithApples; //cambio a sprite arbol con manzanas.
         *      }
         *  }
         *  else if(!leavesWithApples.activeSelf){ leavesWithApples.SetActive(true); }
         * }
         */

        //Comprobación para la actualizacion de las propiedades visuales.
        if (manager.objectToMove == gameObject || selected ||
            GetComponent <MovableObject>().GetComponent <SpriteRenderer>().color != trunk.GetComponent <SpriteRenderer>().color ||
            GetComponent <MovableObject>().GetComponent <SpriteRenderer>().sortingOrder != trunk.GetComponent <SpriteRenderer>().sortingOrder)
        {
            updateVisualProperties();
        }


        //Muestra y oculta elementos dependiendo del estado del objeto.
        if (GetComponent <MovableObject>().objectState == "Waiting")
        {
            shadow.SetActive(true);
        }
        else
        {
            shadow.SetActive(false);
        }

        treeMovementAnimation(); //animacion arrastre del arbol.

        /*switch (treeState)
         * {
         *  case "Touched":
         *     manager.zoomIn(transform.position);
         *     manager.selectionScreen.SetActive(true);
         *     break;
         *
         * }*/


        if (selected)
        {
            if (manager.getSceneState() == "DecisionBox")
            {
                anim.SetBool("Selected", true);
            }
            else
            {
                selected = false;
                anim.SetBool("Selected", false);
            }
        }
    }