Exemplo n.º 1
0
    /// <summary>
    /// Fired when something enters our front collider
    /// </summary>
    /// <param name="other">Other.</param>
    void OnTriggerEnter(Collider other)
    {
        // First, did we enter someone else's Trigger box?
        if (!other.isTrigger)
        {
            // Something is in our collider, don't walk
            canWalk = false;

            // If this is a friendly unit, listen fo death events
            UnitMovement otherUM = other.GetComponent <UnitMovement> ();
            if (otherUM != null && otherUM.enemyTag == enemyTag)
            {
                otherUM.DeathEvent += FriendDeath;
            }
        }

        // If we entered someone else trigger, don't do anything

        // Special case, did we enter the trigger of an enemy outpost?
        else if (other.CompareTag(enemyTag))
        {
            // Use the spawner to check if this is an outpost
            OutpostSpawner tempOutpost = other.GetComponent <OutpostSpawner>();

            if (tempOutpost != null)
            {
                // This is an enemy outpost, stop!
                canWalk = false;
            }
        }
    }
Exemplo n.º 2
0
    // Events
    /// <summary>
    /// Listens for Death events from our Outposts
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="args">Arguments.</param>
    public void SpawnerDeath(object sender, CombatEventArgs args)
    {
        // Sanity check! Is this an OutpostCombat? Is destoryed?
        if (!(sender is OutpostCombat) || sender == null)
        {
            // Make sure this never happens again...
            (sender as OutpostCombat).CombatEvent -= SpawnerDeath;
            return;
        }
        // We only care about death events
        if (args.Message != CombatEventArgs.CombatMsg.IsDefeated)
        {
            // Ignore
            return;
        }

        OutpostCombat  senderOC = sender as OutpostCombat;
        OutpostSpawner senderOS = senderOC.GetComponent <OutpostSpawner>();

        // Remove it from our list
        ourOutposts.Remove(senderOS);

        // Unsubscribe from its event
        senderOC.CombatEvent -= SpawnerDeath;
    }
Exemplo n.º 3
0
    // Methods
    /// <summary>
    /// Spawns the specified unit.
    /// </summary>
    /// <param name="spawnHere">Where the new unit is to be spawned.</param>
    /// <param name="spawnUnit">The unit to be spawned.</param>
    public void SpawnUnit(OutpostSpawner spawnHere, UnitInfo spawnUnit)
    {
        // Sanity checks!
        // Is it on our team? Has it been destroyed? Is this a valid unit?
        if (spawnHere.tag != tag || spawnHere == null || spawnUnit == null)
        {
            // Ignore
            return;
        }

        // Ignore it if we can't afford this unit
        if (ourTreasure.Funds < spawnUnit.unitCost)
        {
            return;
        }

        // Now, attempt to spawn the unit
        if (spawnHere.SpawnUnit(spawnUnit.unitPreFab))
        {
            // Spawn was successful! Deduct it from the treasury
            ourTreasure.Funds -= spawnUnit.unitCost;
        }
    }
Exemplo n.º 4
0
 void Awake()
 {
     instance = this;
 }