Ejemplo n.º 1
0
    IEnumerator BuscaEntidades()
    {
        zombie   = GameObject.FindGameObjectsWithTag("Zombie");
        aldeanos = GameObject.FindGameObjectsWithTag("Aldeano");

        foreach (GameObject objeto in aldeanos)
        {
            yield return(new WaitForEndOfFrame());

            Pueblo.Pueblerino componenteAldeano = objeto.GetComponent <Pueblo.Pueblerino>();
            if (componenteAldeano != null)
            {
                trecho1 = Mathf.Sqrt(Mathf.Pow((objeto.transform.position.x - transform.position.x), 2) + Mathf.Pow((objeto.transform.position.y - transform.position.y), 2) + Mathf.Pow((objeto.transform.position.z - transform.position.z), 2));
                if (trecho1 < 5f)
                {
                    time           = 0;
                    info_Ald       = objeto.GetComponent <Pueblo.Pueblerino>().info_Ald;
                    total_Ald.text = "Hola soy un " + info_Ald.apodo + " y he cumpido " + info_Ald.años.ToString() + " años";
                }
                if (time > 3)
                {
                    total_Ald.text = " ";
                }
            }
        }

        foreach (GameObject itemZ in zombie)
        {
            yield return(new WaitForEndOfFrame());

            Zomb.Zombie componenteZombie = itemZ.GetComponent <Zomb.Zombie>();
            if (componenteZombie != null)
            {
                trecho2 = 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 (trecho2 < 5f)
                {
                    time            = 0;
                    info_Zomb       = itemZ.GetComponent <Zomb.Zombie>().info_Zomb;
                    total_Zomb.text = "Grrrrrrrrrrrr Comida, comidaaaaa Grrr " + info_Zomb.sabor;
                }
                if (time > 3)
                {
                    total_Zomb.text = " ";
                }
            }
        }
        yield return(new WaitForSeconds(0.1f));

        StartCoroutine(BuscaEntidades());
    }
Ejemplo n.º 2
0
            IEnumerator localizar_Ald()
            {
                aldeanos = GameObject.FindGameObjectsWithTag("Aldeano");
                heroe    = GameObject.FindGameObjectWithTag("Hero");
                foreach (GameObject objeto in aldeanos)
                {
                    yield return(new WaitForEndOfFrame());

                    Pueblo.Pueblerino componenteAldeano = objeto.GetComponent <Pueblo.Pueblerino>();
                    if (componenteAldeano != null)
                    {
                        trecho2 = 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));
                        trecho1 = Mathf.Sqrt(Mathf.Pow((objeto.transform.position.x - transform.position.x), 2) + Mathf.Pow((objeto.transform.position.y - transform.position.y), 2) + Mathf.Pow((objeto.transform.position.z - transform.position.z), 2));
                        if (!persecucion)
                        {
                            if (trecho1 < 5f)
                            {
                                estado_Zomb = Estado.Seguir;
                                objetivo    = objeto;
                                persecucion = true;
                            }
                            else if (trecho2 < 5f)
                            {
                                estado_Zomb = Estado.Seguir;
                                objetivo    = heroe;
                                persecucion = true;
                            }
                        }
                        if (trecho1 < 5f && trecho2 < 5f)
                        {
                            objetivo = objeto;
                        }
                    }
                }

                if (persecucion)
                {
                    if (trecho1 > 5f && trecho2 > 5f)
                    {
                        persecucion = false;
                    }
                }

                yield return(new WaitForSeconds(0.1f));

                StartCoroutine(localizar_Ald());
            }