Пример #1
0
    public void SetEstadoInicial(string id, int accion)
    {
        if (string.IsNullOrEmpty(id))
        {
            return;
        }

        var animal   = GameObject.Find(id);
        var animator = animal != null?animal.GetComponent <Animator>() : null;

        if (animator != null && accion > -1)
        {
            var nombreAnimacion = AnimacionesAnimales.GetNombreAnimacion(animator.name, accion);

            if (!string.IsNullOrEmpty(nombreAnimacion))
            {
                animator.Play(nombreAnimacion);

                if (accion == AnimacionesAnimales.ACCION_DORMIR)
                {
                    SetDormido(animator.name, true);
                }
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        //dejando esta linea afuera el canvas se actualiza su posision
        canvas.transform.LookAt(myCamera.transform);
        if (canvas != null && animTransform != null)
        {
            canvas.transform.position = new Vector3(animTransform.position.x + 1, animTransform.position.y + 3, animTransform.position.z);

            if (myCamera != null)
            {
                canvas.transform.LookAt(myCamera.transform);
            }
        }

        if (Input.GetKeyDown(KeyCode.B) || Input.GetKeyDown(Botones.BOTON_R2))
        {
            if (bInfo.activeSelf)
            {
                ActionVolverVerInfo();
            }
            else
            {
                MostrarMenu(false);
                ActionDeseleccionar();
            }
        }

        if (interaccion > -1 && (Input.GetKeyDown(KeyCode.T) || Input.GetKeyDown(Botones.BOTON_R1)))
        {
            MostrarMenu(false);
            bVolver.GetComponent <Button>().interactable = true;
            bDormir.GetComponent <Button>().enabled      = true;

            if (interaccion == AnimacionesAnimales.ACCION_DESELECCIONAR)
            {
                ActionDeseleccionar();
            }
            if (interaccion == AnimacionesAnimales.ACCION_VOLVER_VER_INFO)
            {
                ActionVolverVerInfo();
            }
            else if (interaccion == AnimacionesAnimales.ACCION_VER_INFO)
            {
                //bInfo y bVolver estan debajo del plano al cargar la escena
                if (bInfo.transform.localPosition.y == -1000)
                {
                    bInfo.transform.localPosition = new Vector3(
                        bInfo.transform.localPosition.x,
                        37,
                        bInfo.transform.localPosition.z);
                }

                if (bVolver.transform.localPosition.y == -1000)
                {
                    bVolver.transform.localPosition = new Vector3(
                        bVolver.transform.localPosition.x,
                        -120,
                        bVolver.transform.localPosition.z);
                }

                bInfo.SetActive(true);
                bVolver.SetActive(true);
                interaccion = -1;

                // El animator name es el nombre del game object completo en unity. Ej "Low_Bear_v01", "Low_Bear_v01 (1)"
                // En las funciones de buscarInfo del animal y GetNombreAnimacion, hay que usar el nombre base (para los dos osos sería "Low_Bear_v01")
                // En esas funciones, hacer un split del animator.name, usando el espacio como caracter separador

                string info = BuscarInfo(animator.name);
                GameObject.Find("bInfo").GetComponentInChildren <Text>().text = info;
            }
            else
            {
                if (interaccion == AnimacionesAnimales.ACCION_DORMIR)
                {
                    GetComponent <EstadoAnimales>().SetDormido(animator.name, true);
                }
                else if (interaccion == AnimacionesAnimales.ACCION_DESPERTAR)
                {
                    GetComponent <EstadoAnimales>().SetDormido(animator.name, false);
                }

                if (animator != null && interaccion > -1)
                {
                    // Animaciones.Animales es el script que tiene los diccionarios (nombre de animaciones por animal, info de animales)

                    // El animator name es el nombre del game object completo en unity. Ej "Low_Bear_v01", "Low_Bear_v01 (1)"
                    // En las funciones de buscarInfo del animal y GetNombreAnimacion, hay que usar el nombre base (para los dos osos sería "Low_Bear_v01")
                    // En esas funciones, hacer un split del animator.name, usando el espacio como caracter separador

                    var nombreAnimacion = AnimacionesAnimales.GetNombreAnimacion(animator.name, interaccion);

                    if (!string.IsNullOrEmpty(nombreAnimacion))
                    {
                        if (interaccion == AnimacionesAnimales.ACCION_COMER)
                        {
                            animator.gameObject.GetComponent <comida>().enabled = true;
                        }
                        animator.Play(nombreAnimacion);

                        if (interaccion == AnimacionesAnimales.ACCION_CORRER)
                        {
                            animator.gameObject.GetComponent <Correr>().enabled = true;
                        }
                    }
                }
            }

            GetComponent <MenuInteracciones>().animator = null;
            GetComponent <MenuInteracciones>().enabled  = false;
            interaccion = -1;
        }
    }