Exemplo n.º 1
0
    /// <summary>
    /// la distancia para el activamiento del hub
    /// </summary>
    /// <returns></returns>
    IEnumerator BuscaEntidades()
    {
        zombie   = GameObject.FindGameObjectsWithTag("Zombie");
        aldeanos = GameObject.FindGameObjectsWithTag("Villager");

        // Hub  para el aldeano
        foreach (GameObject item in aldeanos)
        {
            yield return(new WaitForEndOfFrame());

            ald.Villager componenteAldeano = item.GetComponent <ald.Villager>();
            if (componenteAldeano != null)
            {
                distancia = Mathf.Sqrt(Mathf.Pow((item.transform.position.x - transform.position.x), 2) + Mathf.Pow((item.transform.position.y - transform.position.y), 2) + Mathf.Pow((item.transform.position.z - transform.position.z), 2));
                if (distancia < 5f)
                {
                    time              = 0;
                    infoAlde          = item.GetComponent <ald.Villager>().infoAlde;
                    textoAldeano.text = "Hola, soy " + infoAlde.name + " y tengo " + infoAlde.edad.ToString() + " años";
                }
                if (time > 3)
                {
                    textoAldeano.text = " ";
                }
            }
        }

        // Hub para el zombie
        foreach (GameObject itemZ in zombie)
        {
            yield return(new WaitForEndOfFrame());

            zom.Zombie componenteZombie = itemZ.GetComponent <zom.Zombie>();
            if (componenteZombie != null)
            {
                distanciaZ = Mathf.Sqrt(Mathf.Pow((itemZ.transform.position.x - transform.position.x), 2) + Mathf.Pow((itemZ.transform.position.y - transform.position.y), 2) + Mathf.Pow((itemZ.transform.position.z - transform.position.z), 2));
                if (distanciaZ < 5f)
                {
                    time             = 0;
                    infoZombie       = itemZ.GetComponent <zom.Zombie>().infoZombie;
                    textoZombie.text = "Waaaarrrr quiero comer " + infoZombie.gusto;
                }
                if (time > 3)
                {
                    textoZombie.text = " ";
                }
            }
        }
        yield return(new WaitForSeconds(0.1f));

        StartCoroutine(BuscaEntidades());
    }
Exemplo n.º 2
0
            /// <summary>
            /// corutina encargada del estado pursuing del zombie
            /// </summary>
            /// <returns></returns>
            IEnumerator buscaAldeanos()
            {
                heroe    = GameObject.FindGameObjectWithTag("Hero");
                aldeanos = GameObject.FindGameObjectsWithTag("Villager");
                foreach (GameObject item in aldeanos)
                {
                    yield return(new WaitForEndOfFrame());

                    villa.Villager componenteAldeano = item.GetComponent <villa.Villager>();
                    if (componenteAldeano != null)
                    {
                        distanciaH = Mathf.Sqrt(Mathf.Pow((heroe.transform.position.x - transform.position.x), 2) + Mathf.Pow((heroe.transform.position.y - transform.position.y), 2) + Mathf.Pow((heroe.transform.position.z - transform.position.z), 2));
                        distancia  = Mathf.Sqrt(Mathf.Pow((item.transform.position.x - transform.position.x), 2) + Mathf.Pow((item.transform.position.y - transform.position.y), 2) + Mathf.Pow((item.transform.position.z - transform.position.z), 2));
                        if (!pursuingState)
                        {
                            if (distancia < 5f)
                            {
                                zombieEstado  = Estado.Pursuing;
                                Target        = item;
                                pursuingState = true;
                            }
                            else if (distanciaH < 5f)
                            {
                                zombieEstado  = Estado.Pursuing;
                                Target        = heroe;
                                pursuingState = true;
                            }
                        }
                        if (distancia < 5f && distanciaH < 5f)
                        {
                            Target = item;
                        }
                    }
                }

                if (pursuingState)
                {
                    if (distancia > 5f && distanciaH > 5f)
                    {
                        pursuingState = false;
                    }
                }

                yield return(new WaitForSeconds(0.1f));

                StartCoroutine(buscaAldeanos());
            }