Ejemplo n.º 1
0
    // instantiate a new soldier
    public void InstantiateSoldier()
    {
        SoldierSlot availableSlot = getAvailableSlot();

        // no place was found
        if (availableSlot == null)
        {
            print(string.Format("Tower {0} - No free slots", playerNumber));
        }

        // instantiate a new soldier and target it towards the free soldier slot
        else
        {
            setGateOpen(true);

            GameObject newSoldier = Instantiate(soldierPrefab,
                                                soldierInstantiatePosition.position,
                                                Quaternion.LookRotation(-transform.forward, transform.up),
                                                transform) as GameObject;
            newSoldier.GetComponent <SortingGroup>().sortingOrder = countNumOfSoldiers;
            SoldierHealth newSoldierComponent = newSoldier.GetComponent <SoldierHealth>();
            newSoldierComponent.spawnPoint  = soldierInstantiatePosition;
            newSoldierComponent.soldierSlot = availableSlot;
            //newSoldierComponent.speed = 10;

            currentNumOfSoldiers++;
            countNumOfSoldiers++;

            //Invoke("closeGate", delayBeforeClosingTheGate);
        }
    }
Ejemplo n.º 2
0
    // activated after a soldier came back to the tower's gate gate
    public void OnSoldierIsBack(SoldierSlot soldierSlotToFree)
    {
        currentNumOfSoldiers--;

        // free the soldierSlot
        foreach (SoldierSlot slot in soldierSlots)
        {
            if (slot == soldierSlotToFree)
            {
                slot.isFree = true;
            }
        }
        Invoke("InstantiateSoldier", delayBeforeInstantiating);
    }
Ejemplo n.º 3
0
    //public void openGate()
    //{
    //    setGateOpen(true);
    //}
    //public void closeGate()
    //{
    //    setGateOpen(false);
    //}

    // returns a free SoldierSlot or null if it's all taken
    SoldierSlot getAvailableSlot()
    {
        // search for a free soldier slot
        SoldierSlot availableSlot = null;

        foreach (SoldierSlot slot in soldierSlots)
        {
            if (slot.isFree)
            {
                availableSlot = slot;
                slot.isFree   = false; // mark the spot as taken
                break;
            }
        }

        return(availableSlot);
    }