Ejemplo n.º 1
0
    // Update is called once per frame
    public void Update()
    {
        for (int i = 0; i < (ENEMY_CAP - TurretManager.NumAlive()); i++)
        {
            //Spawn stuff here
            if (i < EnemiesToSpawn.Count)
            {
                TurretManager.PlaceTurret(TurretManager.turret_types[EnemiesToSpawn[0]], GetRandomValidPosition(EnemiesToSpawn[0]));
                EnemiesToSpawn.RemoveAt(0);
            }
        }

        if (player.GetComponent <Player>().won)
        {
            if (Input.GetButtonDown("Fire1"))
            {
                Application.LoadLevel("Minigame 1");
            }
            else if (Input.GetButtonDown("Fire2"))
            {
                                #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
                                #else
                System.Diagnostics.Process.GetCurrentProcess().Kill();
                                #endif
            }
        }

        //Check if player is dead
        if (!player.GetComponent <Player>().IsAlive())
        {
            if (!fading)
            {
                fading = true;
                StartCoroutine(player.GetComponent <Player>().FadeToBlack());
                //Disable turrets that are still alive
                StartCoroutine(TurretManager.KillAll());

                //Disable powers
                GameObject[] hands = new GameObject[2];
                hands[0] = left;
                hands[1] = right;

                //remove preset powers
                foreach (GameObject hand in hands)
                {
                    foreach (Component comp in hand.GetComponents(typeof(MonoBehaviour)))
                    {
                        Destroy(comp);
                    }
                }
            }

            if (Input.GetButtonDown("Fire1"))
            {
                Application.LoadLevel("Minigame 1");
            }
            else if (Input.GetButtonDown("Fire2"))
            {
                #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
                #else
                System.Diagnostics.Process.GetCurrentProcess().Kill();
                #endif
            }
        }
        else
        {
            //Check if the round is over

            if (EnemiesToSpawn.Count == 0 && TurretManager.NumAlive() == 0 && !roundTimer.active)
            {
                roundTimer.Start();
            }

            roundTimer.Update();

            //Check if we are done waiting
            if (roundTimer.Complete())
            {
                roundTimer.Stop();
                roundTimer.Restart();

                this.currentRound++;

                TurretManager.ClearSpawned();

                player.GetComponent <Player>().health = 25f;

                this.ReadRoundData(currentRound);

                if (TurretManager.NumAlive() == 0 && EnemiesToSpawn.Count == 0)
                {
                    player.GetComponent <Player>().won = true;
                    healthBar.SetActive(false);

                    if (!fading)
                    {
                        fading = true;
                        StartCoroutine(player.GetComponent <Player>().WinAnimation());

                        //Disable turrets that are still alive
                        StartCoroutine(TurretManager.KillAll());

                        //Disable powers
                        GameObject[] hands = new GameObject[2];
                        hands[0] = left;
                        hands[1] = right;

                        //remove preset powers
                        foreach (GameObject hand in hands)
                        {
                            foreach (Component comp in hand.GetComponents(typeof(MonoBehaviour)))
                            {
                                Destroy(comp);
                            }
                        }
                    }
                }
            }
        }
    }