public void Spawn(Unit.UnitType type, Vector2 position, Vector2 targetPosition, Unit.PlayerTag player)
    {
        GameObject unitObject = null;
        Transform  location   = player == Unit.PlayerTag.PLAYER_1 ? m_p1Units : m_p2Units;

        switch (type)
        {
        case Unit.UnitType.DRAGON:
            GameObject unit1 = player == Unit.PlayerTag.PLAYER_1 ? m_dragonTemplateBlue : m_dragonTemplateRed;
            unitObject = Instantiate(unit1, position, Quaternion.identity, location);
            break;

        case Unit.UnitType.CATAPULT:
            GameObject unit2 = player == Unit.PlayerTag.PLAYER_1 ? m_catapultTemplateBlue : m_catapultTemplateRed;
            unitObject = Instantiate(unit2, position, Quaternion.identity, location);
            break;

        case Unit.UnitType.ARCHER:
            GameObject unit3 = player == Unit.PlayerTag.PLAYER_1 ? m_archerTemplateBlue : m_archerTemplateRed;
            unitObject = Instantiate(unit3, position, Quaternion.identity, location);
            break;
        }
        Unit unit = unitObject.GetComponent <Unit>();

        unit.m_actualPosition = transform.position;
        unit.SetTargetPosition(targetPosition);
        UnitManager.Instance.AddUnit(unit);
    }
Ejemplo n.º 2
0
    private List <Unit> GetFriendlies(Unit.PlayerTag tag)
    {
        List <Unit> units = new List <Unit>();

        foreach (Unit unit in m_units)
        {
            if (unit.m_playerTag == tag)
            {
                units.Add(unit);
            }
        }

        return(units);
    }