Exemplo n.º 1
0
    //actual spawning routine, responsible for spawning one type of creep only
    IEnumerator SpawnSubwave(SubWave subWave, Wave parentWave, int waveID)
    {
        yield return(new WaitForSeconds(subWave.delay));

        int spawnCount = 0;

        while (spawnCount < subWave.count)
        {
            Vector3    pos;
            Quaternion rot;

            PathTD tempPath;
            if (subWave.path == null)
            {
                tempPath = defaultPath;
            }
            else
            {
                tempPath = subWave.path;
            }

            pos = tempPath.waypoints[0].position;
            rot = tempPath.waypoints[0].rotation;

            GameObject obj = ObjectPoolManager.Spawn(subWave.unit, pos, rot);
            //Unit unit=obj.GetComponent<Unit>();
            UnitCreep unit = obj.GetComponent <UnitCreep>();

            if (subWave.overrideHP > 0)
            {
                unit.SetFullHP(subWave.overrideHP);
            }
            if (subWave.overrideShield > 0)
            {
                unit.SetFullShield(subWave.overrideShield);
            }
            if (subWave.overrideMoveSpd > 0)
            {
                unit.SetMoveSpeed(subWave.overrideMoveSpd);
            }
            if (subWave.overrideLifeCost >= 0)
            {
                unit.SetLifeCost(subWave.overrideLifeCost);
            }
            bool overrideValue = false;
            if (subWave.overrideValue.Length >= 0)
            {
                foreach (float val in subWave.overrideValue)
                {
                    if (val > 0)
                    {
                        overrideValue = true;
                    }
                }
            }
            if (overrideValue)
            {
                unit.SetValue(subWave.overrideValue);
            }

            unit.Init(tempPath, totalSpawnCount, waveID);
            unit.pathLooping = pathLooing;

            totalSpawnCount += 1;

            parentWave.activeUnitCount += 1;

            spawnCount += 1;
            if (spawnCount == subWave.count)
            {
                break;
            }

            yield return(new WaitForSeconds(subWave.interval));
        }

        subWave.spawned = true;
    }