Ejemplo n.º 1
0
    void Update()
    {
        RallyPoint();

        //UIItems();
        UpgradeSlot();


        //timer resetea cada vez que cambia de dueño la zona
        if (lastBuildingState != buildingState)
        {
            currentTime = cooldownToSpawn;
        }

        //el timer se ejecuta si la bandera no está en modo neutral y si las lista de los objectos no ha llegado a su máximo
        if (buildingState == Zone.STATE.Player)
        {
            if (playerList.Count < maxTroops)
            {
                currentTime -= Time.deltaTime;
            }
        }
        if (buildingState == Zone.STATE.AI)
        {
            if (enemyList.Count < enemyMaxTroops)
            {
                currentTime -= Time.deltaTime;
            }
        }

        //spawns dependiendo de quien controla la zona
        PlayerSpawn();
        AISpawn();

        if (spawnDirectly) //Spawn de unidades inicial, sin tener ue esperar X tiempo a cada reaparición de unidades
        {
            #region Spawn when game starts
            GameObject directSpawnObject = objectPooler.GetPooledObject(playerObjectPoolTag);
            directSpawnObject.GetComponent <Unit_Base>().buildingTag = gameObject.tag;

            if (directSpawnObject != null)
            {
                //listas a añadir el GameObject creado
                playerList.Add(directSpawnObject);
                objectPooler.activePooledObjects.Add(directSpawnObject);
                //sitio en el que aparecer
                directSpawnObject.transform.position = spawnPoint.position;
                directSpawnObject.transform.rotation = spawnPoint.rotation;

                //que se vea el objecto
                directSpawnObject.SetActive(true);
                //Donde se mueve al aparecer
                directSpawnObject.GetComponent <Unit_Base>().MoveAt(GetRandomPosition());
            }
            #endregion

            instantUnits++;
            print("spawns");
        }
        if (instantUnits >= startUnits)
        {
            spawnDirectly = false;
        }

        ;

        //timer dueño (realción con la primera condición)
        lastBuildingState = buildingState;
    }