示例#1
0
            IEnumerator localizar_Zomb()
            {
                aldeanos = GameObject.FindGameObjectsWithTag("Zombie");
                foreach (GameObject objeto in aldeanos)
                {
                    Zomb.Zombie componenteZombie = objeto.GetComponent <Zomb.Zombie>();
                    if (componenteZombie != null)
                    {
                        distancia = 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 (!estado_Escape)
                        {
                            if (distancia < 5f)
                            {
                                estadoVillager = Estado.escape;
                                objetivo       = objeto;
                                estado_Escape  = true;
                            }
                        }
                    }
                }

                if (estado_Escape)
                {
                    if (distancia > 5f)
                    {
                        estado_Escape = false;
                    }
                }

                yield return(new WaitForSeconds(0.1f));

                StartCoroutine(localizar_Zomb());
            }
示例#2
0
文件: Heroe.cs 项目: DanCG002/Taller4
    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());
    }