Exemplo n.º 1
0
    public void Evolve(AttackComponent element)
    {
        List <Unit> unitsToEvolve = new List <Unit>();

        foreach (Unit unit in unitHolder.hashUnits)
        {
            if (unit.TryGetComponent <Warrior>(out Warrior warrior) && unit.team == Team.Player)
            {
                unitsToEvolve.Add(unit);
            }

            if (unitsToEvolve.Count == 2)
            {
                break;
            }
        }

        foreach (Unit unit in unitsToEvolve)
        {
            unit.health.TakeDamage(1000);
        }

        Unit spawnedUnit = Instantiate(Resources.Load("Warrior_empty", typeof(Unit)) as Unit, transform.position, Quaternion.identity);

        Instantiate(element.attackComponentPrefab, spawnedUnit.transform.position, element.attackComponentPrefab.transform.rotation, spawnedUnit.transform);

        SpriteRenderer renderer = spawnedUnit.GetComponentInChildren <SpriteRenderer>();

        renderer.color  = element.color;
        renderer.sprite = element.unitSprite;

        unitHolder.AddUnit(spawnedUnit);
    }
Exemplo n.º 2
0
 private void Update()
 {
     if (unitHolder.hashUnits.Count < capacity && Time.time >= timeUntilNextSpawn)
     {
         GameObject unit = Instantiate(unitToSpawn, transform.position, Quaternion.identity);
         unitHolder.AddUnit(unit.GetComponent <Unit>());
         timeUntilNextSpawn = Time.time + spawnTime;
     }
 }