Пример #1
0
    void Start()
    {
        heroe = GameObject.CreatePrimitive(PrimitiveType.Cube); //crea pers heroe
        heroe.AddComponent <PersHero>();                        //adiere componentes
        heroe.AddComponent <MoviFps>();
        heroe.AddComponent <Rigidbody>();
        GameObject movCam = new GameObject(); //crea un objeto para añadirle la camara y el script de movimiento de camara y hacerlo hijo del heroe

        movCam.AddComponent <Camera>();
        movCam.AddComponent <CamFps>();
        movCam.transform.SetParent(heroe.transform);
        heroe.transform.position = new Vector3(rnd.Next(5, 24), 0.5f, rnd.Next(5, 24));
        heroe.name = "heroe";

        int cantidad = rnd.Next(minimo, maximo); //var para crear numero random de personajes

        for (int i = 0; i < cantidad; i++)       //crea los personajes segun cantidad
        {
            int escojer = rnd.Next(0, 2);
            if (escojer == 0)                                           //segun escojer crea un zombi o un ciudadano
            {
                zombi = GameObject.CreatePrimitive(PrimitiveType.Cube); //crea zombi y adiere componentes
                zombi.AddComponent <NamNPC.NamEnemy.Zombi>();
                zombi.transform.position = zombi.GetComponent <NamNPC.NamEnemy.Zombi>().mov;
                utilZombi = zombi.GetComponent <NamNPC.NamEnemy.Zombi>().utilZom;
                zombi.GetComponent <Renderer>().material.color = utilZombi.colorZombi;
                zombi.AddComponent <Rigidbody>();
                zombi.name = "Zombi";
            }
            else
            {
                ciudadano = GameObject.CreatePrimitive(PrimitiveType.Cube); //crea ciudadano y adiere componentes
                ciudadano.AddComponent <NamNPC.NamAlly.Ciudadano>();
                ciudadano.transform.position = new Vector3(rnd.Next(1, 20), 0.5f, rnd.Next(1, 20));
                ciudadano.AddComponent <Rigidbody>();
                ciudadano.name = "Ciudadanito";
            }
        }

        numCiuda = 0;
        foreach (NamNPC.NamAlly.Ciudadano i in Transform.FindObjectsOfType <NamNPC.NamAlly.Ciudadano>()) //busca todos los objetos con el componente ciudadanno para ir sumando numCiuda y mostrar en pantalla
        {
            numCiuda += 1;
        }

        numZomb = 0;
        foreach (Zombi i in Transform.FindObjectsOfType <Zombi>()) //busca todos los objetos con el componente zombi para ir sumando numZomb y mostrar en pantalla
        {
            numZomb += 1;
        }
        contZombi.text = "zombi: " + numZomb;      //muestra numero de zombis
        contCiud.text  = "ciudadano: " + numCiuda; //muestra numero de ciudadanos
    }
Пример #2
0
    void Start()
    {
        heroe = GameObject.CreatePrimitive(PrimitiveType.Cube); //creacion de heroe
        heroe.AddComponent <PersHero>();
        heroe.AddComponent <MoviFps>();
        heroe.AddComponent <Rigidbody>();
        GameObject movCam = new GameObject(); // objeto para añadirle la camara y el script de la camara y este añadirlo al heroe

        movCam.AddComponent <Camera>();
        movCam.AddComponent <CamFps>();
        movCam.transform.SetParent(heroe.transform);
        heroe.transform.position = new Vector3(rnd.Next(5, 24), 0.5f, rnd.Next(5, 24));

        int cantidad = rnd.Next(minimo, maximo); //random para crear personajes

        for (int i = 0; i < cantidad; i++)       //for para crear numero de personajes
        {
            int escojer = rnd.Next(0, 2);        //segun random se crea un zombi o ciudadano
            if (escojer == 0)                    //si es cero crea zombi
            {
                zombi = GameObject.CreatePrimitive(PrimitiveType.Cube);
                zombi.AddComponent <NamNPC.NamEnemy.Zombi>();
                zombi.transform.position = zombi.GetComponent <NamNPC.NamEnemy.Zombi>().mov; //da posicion al zombi
                utilZombi = zombi.GetComponent <NamNPC.NamEnemy.Zombi>().utilZom;
                zombi.GetComponent <Renderer>().material.color = utilZombi.colorZombi;
                zombi.AddComponent <Rigidbody>();
                zombi.name = "Zombi";
            }
            else //si no crea un ciudadano
            {
                ciudadano = GameObject.CreatePrimitive(PrimitiveType.Cube);
                ciudadano.AddComponent <NamNPC.NamAlly.Ciudadano>();
                ciudadano.transform.position = ciudadano.GetComponent <NamNPC.NamAlly.Ciudadano>().ubic;
                ciudadano.AddComponent <Rigidbody>();
                ciudadano.name = "Ciudadanito";
            }
        }

        numZomb = 0;                                               //variable para contar los zombis
        foreach (Zombi i in Transform.FindObjectsOfType <Zombi>()) //si el objeto de la escena tiene el componente zombi, que cuente 1
        {
            numZomb += 1;
        }
        contZombi.text = "Zombi: " + numZomb;                                                            //para mostrar la cantidad de zombis en pantalla

        numCiud = 0;                                                                                     //variable para contar los zombis
        foreach (NamNPC.NamAlly.Ciudadano i in Transform.FindObjectsOfType <NamNPC.NamAlly.Ciudadano>()) //si el objeto de la escena tiene el componente ciudadano, que cuente 1
        {
            numCiud += 1;
        }
        contCiud.text = "Ciudadano: " + numCiud; //para mostrar la cantidad de ciudadanos en pantalla
    }