예제 #1
0
파일: SpawnEnemy.cs 프로젝트: ZrbTz/Droids
    private void AddSpawnDataToMiniMap(BigHorde bigHorde)
    {
        float time = Time.time;

        foreach (Horde horde in bigHorde.hordes)
        {
            time += horde.delay;
            if (horde.difficulty != HordeDifficulty.None)
            {
                miniMapSpawner.AddSpawnData(time, horde.difficulty);
            }
            time += horde.tempoPerSpawnare;
        }
    }
예제 #2
0
파일: SpawnEnemy.cs 프로젝트: ZrbTz/Droids
    /*IEnumerator RandomicSpawn(BigHorde bigHorde)
     * {
     *  for (int j = 0; j < bigHorde.hordes.Length; j++)
     *  {
     *      yield return new WaitForSeconds(bigHorde.hordes[j].delay);
     *      for (int i = 0; i < bigHorde.hordes[j].count; i++)
     *      {
     *          float timeToWait = Random.Range(0.0f, maxtimeSpawn);
     *          yield return new WaitForSeconds(timeToWait);
     *          while (spawnFreeZones.Count == 0)
     *          {
     *              yield return new WaitForSeconds(1);
     *          }
     *          int indexZone = Random.Range(0, spawnFreeZones.Count - 1);
     *          GameObject selectedZone = spawnFreeZones[indexZone];
     *          spawnFreeZones.RemoveAt(indexZone);
     *          GameObject newEnemy = Instantiate(bigHorde.hordes[j].enemy);
     *          newEnemy.GetComponent<Soldier>().destination = destination;
     *          newEnemy.GetComponent<NavMeshAgent>().Warp(selectedZone.transform.TransformPoint(Vector3.zero));
     *          //newEnemy.transform.position = selectedZone.transform.TransformPoint(Vector3.zero);
     *          newEnemy.transform.rotation = this.transform.rotation;
     *      }
     *  }
     *  gm.signalSpawnEnd();
     *  yield break;
     * }*/

    IEnumerator TimedSpawn(BigHorde bigHorde)
    {
        AddSpawnDataToMiniMap(bigHorde);
        for (int j = 0; j < bigHorde.hordes.Length; j++)
        {
            yield return(new WaitForSeconds(bigHorde.hordes[j].delay));

            float elapsedTime = 0.0f;
            float totTime     = bigHorde.hordes[j].tempoPerSpawnare;
            int   counter     = 0;
            while (elapsedTime < totTime)
            {
                //percentuale tempo passata > percentuale nemici spawnati
                if (elapsedTime / totTime > (float)counter / bigHorde.hordes[j].count)
                {
                    Vector3 spawnPosition;
                    if (SpawnPoint.Length == 0)
                    {
                        spawnPosition = this.transform.position;
                    }
                    else
                    {
                        spawnPosition = SpawnPoint[Random.Range(0, SpawnPoint.Length)].transform.position;
                    }
                    spawnPosition.x = spawnPosition.x + Random.Range(-3.0f, 3.0f);
                    spawnPosition.z = spawnPosition.z + Random.Range(-3.0f, 3.0f);

                    GameObject newEnemy = Instantiate(bigHorde.hordes[j].enemy, spawnPosition, Quaternion.identity);
                    newEnemy.GetComponent <Enemy>().destination = destination;
                    newEnemy.GetComponent <Enemy>().path        = this.path;

                    counter++;
                }
                elapsedTime += Time.deltaTime;
                yield return(new WaitForFixedUpdate());
            }
        }
        gm.signalSpawnEnd();
        yield break;
    }