Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        fpsController        = player.GetComponent <FirstPersonController> ();
        remainingZombies     = 0;
        wave                 = 0;
        spawnLocations       = new List <SpawnLocation>(spawnLocationsContainer.GetComponentsInChildren <SpawnLocation> ());
        ammoSpawnLocations   = new List <ItemSpawnLocation>(ammoSpawnLocationsContainer.GetComponentsInChildren <ItemSpawnLocation> ());
        healthSpawnLocations = new List <ItemSpawnLocation>(healthSpawnLocationsContainer.GetComponentsInChildren <ItemSpawnLocation> ());

        spawnTimer = new CounterTimer(0.5f);
        waveTimer  = new CounterTimer(wavesInterval);
        Status     = Spo2GameStatus.Playing;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Status == Spo2GameStatus.Playing)
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                Status = Spo2GameStatus.Paused;
                return;
            }


            if (remainingZombies <= 0)
            {
                if (wave == waves.Count)
                {
                    Status = Spo2GameStatus.PlayerWins;
                    return;
                }

                wave += 1;
                SoundManager.Instance.PlayClip(newWaveClip);
                waveTimer.Reset();
                remainingZombies = waves [wave - 1];
                waveEnded        = true;
                spawnedZombies   = 0;

                if (healthCount == 0)
                {
                    healthCount = spawnItems(healthSpawnLocations, minAmmoSpawn, maxAmmoSpawn, ItemType.HEALTH);
                }
            }

            if (ammoCount == 0)
            {
                ammoCount = spawnItems(ammoSpawnLocations, minAmmoSpawn, maxAmmoSpawn, ItemType.AMMO);
            }

            if (waveEnded && waveTimer.Finished)
            {
                waveEnded = false;
                Spawn();
            }

            if (!waveEnded && spawnTimer.Finished && spawnedZombies < waves [wave - 1])
            {
                Spawn();
            }

            spawnTimer.Update(Time.deltaTime);
            waveTimer.Update(Time.deltaTime);

            if (player.health <= 0)
            {
                Status = Spo2GameStatus.GameOver;
            }
        }
        else if (Status == Spo2GameStatus.Paused)
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                Status = Spo2GameStatus.Playing;
                return;
            }
        }
    }