Ejemplo n.º 1
0
    /// <summary>
    /// Called when a unit is to enter/attack this tower.
    /// See documenation for full explaination and metrics.
    /// If unit is friendly, stationed units is increased.
    /// Raises ChangedFaction and AttackedByUnit events.
    /// </summary>
    /// <param name="unit">Unit.</param>
    public void UnitEntered(UnitBehavior unit)
    {
        if (unit.Faction == Faction)
        {
            // Friendly units are transfered to this towers group
            unit.TransferGroup(stationedGroup);
            unit.gameObject.SetActive(false);
        }
        else
        {
            // Hostile units damage this towers stationed unit group
            int strength = FactionController.GetAttackStrengthForFaction(unit.Faction);
            stationedGroup.Damage(strength);

            // Change tower's faction if last unit was killed
            if (stationedGroup.Empty)
            {
                TowerController.ConvertTowerToFaction(this, unit.Faction);
                if (ChangedFaction != null)
                {
                    ChangedFaction(Faction);
                    SetGraphic();
                }
            }

            unit.ImpactKill();

            if (AttackedByUnit != null)
            {
                AttackedByUnit(unit);
            }
        }
    }
Ejemplo n.º 2
0
    public void Drive()
    {
        upTime += Time.deltaTime;
        float frac = Mathf.Clamp01(upTime / animTime);
        float x    = frac * (Mathf.PI / 2);

        unit.transform.position = Vector3.Lerp(origin, destination, Mathf.Sin(x)) + originTower.transform.position;
        if (Vector3.Distance(unit.transform.position, originTower.transform.position) <= .1f && deactivate)
        {
            unit.ImpactKill();
            originTower = null;
        }
    }