Example #1
0
    void OnTriggerEnter(Collider collider_)
    {
        Town town = collider_.gameObject.GetComponent <Town>();

        // we may have no population if we collided with another army or if we collided with the town we left, do nothing
        if (GetPopulation() == 0 || town == townFrom)
        {
            return;
        }

        if (town != null)
        {
            Town.AttackTown(town, this);
            return;
        }

        Army army = collider_.gameObject.GetComponent <Army>();

        if (army != null)
        {
            Army.AttackArmy(this, army);

            if (GetPopulation() == 0)
            {
                Destroy(this.gameObject);
            }

            if (army.GetPopulation() == 0)
            {
                Destroy(army.gameObject);
            }
        }
    }