Exemple #1
0
    public override void spawnTeam()
    {
        controllerID = 1;
        List <unitScript> team = new List <unitScript>();

        EnemyType[] types = map.getEnemyTypes();
        Dictionary <Vector2, int> spawnData = map.getSpawnData();

        foreach (Vector2 position in spawnData.Keys)
        {
            if (spawnData[position] >= 2)            // If greater than 2 then spawn enemy
            {
                EnemyType type = types[spawnData[position]];

                GameObject newUnit = (GameObject)Instantiate(Resources.Load(type.source), transform, true);
                unitScript unit    = newUnit.GetComponent <unitScript>();

                unit.setData(type.unitName, type.unitClass, type.health, type.speed, type.skill, type.strength, type.smarts, "", new List <string>(type.weapons));
                unit.gameObject.layer = 8;
                unit.setPosition((int)position.x, (int)position.y);
                unit.setOwner(1);
                AIUnitController ai = unit.gameObject.AddComponent <AIUnitController>();
                ai.healthThreshold = type.healthThreshold;
                team.Add(unit);
                unitsInGame.Add(unit);
            }
        }
        playerUnitList = team.ToArray();
    }
Exemple #2
0
    public void addUnit(int typeIndex, int x, int y)
    {
        EnemyType[] types   = map.getEnemyTypes();
        EnemyType   type    = types[typeIndex];
        GameObject  newUnit = (GameObject)Instantiate(Resources.Load(type.source), transform, true);
        unitScript  unit    = newUnit.GetComponent <unitScript>();

        unit.setData(type.unitName, type.unitClass, type.health, type.speed, type.skill, type.strength, type.smarts, "", new List <string>(type.weapons));
        unit.gameObject.layer = 8;
        unit.setPosition(x, y);
        unit.setOwner(1);
        AIUnitController ai = unit.gameObject.AddComponent <AIUnitController>();

        ai.healthThreshold = type.healthThreshold;
        List <unitScript> newList = new List <unitScript>(playerUnitList);

        newList.Add(unit);
        this.playerUnitList = newList.ToArray();
        unitsInGame.Add(unit);
    }