public void StartGame(int difficulty)
 {
     spawnRate = new SpawnRate(difficulty);
     Debug.Log("Spawn rate = " + spawnRate.GetRate());
     titleScreen.gameObject.SetActive(false);
     isGameRunning = true;
     StartCoroutine(TargetSpawner());
     UpdateScore(0);
 }
    IEnumerator TargetSpawner()
    {
        while (isGameRunning)
        {
            yield return(new WaitForSeconds(spawnRate.GetRate()));

            int targetIndex = Random.Range(0, targets.Count);
            Instantiate(targets[targetIndex]);
        }
    }
예제 #3
0
    // While game is active spawn a random target
    IEnumerator SpawnTarget()
    {
        while (isGameActive)
        {
            yield return(new WaitForSeconds(spawnRate.GetRate()));

            int index = Random.Range(0, targetPrefabs.Count);

            if (isGameActive)
            {
                Instantiate(targetPrefabs[index], RandomSpawnPosition(), targetPrefabs[index].transform.rotation);
            }
        }
    }