Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jjdoughboy · Aug 31, 2020 at 08:52 PM · countdownactivate

how do I activate my countdown

I have 4 levels that have a wave countdown before the enemy will spawn, during the countdown the retry button will actually restart the level but once the countdown is done and enemy has spawned if the retry button is pressed at that point the level scene will reload but the wave countdown won't actually start. I'm not to sure why. cans one help me out. its almost like the retry button is saying that when the countdown isn't active than don't activate the countdown on retry.

here is my function its attached to my pause menu script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class PauseMenu : MonoBehaviour
 {
     public GameObject pauseUI;
 
     public GameObject playerPanelUI;
 
     public GameObject shopPanelUI;
 
     public string mainMenu = "MainMenu";
 
 
     // Update is called once per frame
     void Update()
     {
         if(Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.P))
         {
             Toggle();
         }
     }
 
     public void Toggle()
     {
         pauseUI.SetActive(!pauseUI.activeSelf);
 
         if(pauseUI.activeSelf)
         {
             Time.timeScale = 0f;
 
             playerPanelUI.SetActive(false);
             shopPanelUI.SetActive(false);
         }
         else
         {
             Time.timeScale = 1f;
 
             playerPanelUI.SetActive(true);
             shopPanelUI.SetActive(true);
         }
     }
 
     public void Retry()
     {
         Toggle();
 
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
     }
 
     public void Menu()
     {
         SceneManager.LoadScene(mainMenu);
     }
 }
 

Here is my wave countdown function its attached to my wave spawner script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class WaveSpawner : MonoBehaviour
 {
     public Transform enemyPrefab;
     public Transform spawnPoint;
     public float waveInterval = 5f;
     public float countdown = 2f;
 
     private int waveIndex = 0;
 
     public Text waveCountdown;
 
     public Wave[] waves;
 
     public GameManager gameManager;
 
     [Header("How Many Enemies Are Left")]
     public static int EnemiesAlive;
 
     void Update()
     {
         if(EnemiesAlive > 0)
         {
             return;
         }
 
         if (countdown <= 0f)
         {
             // The coroutine will pause execution and automatically
             // resume at the next frame
             // With coroutines we begin to model behavior without affecting performance
             StartCoroutine(SpawnWave());
             Debug.Log("Wave Start");
             countdown = waveInterval;
             return;
         }
 
         if (waveIndex == waves.Length)
         {
             if (EnemiesAlive < 1)
             {
                 this.enabled = false;
                 gameManager.WinLevel();
             }
         }
 
         countdown -= Time.deltaTime;
 
         waveCountdown.text = string.Format("{0:00.00}", countdown);
 
         countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
     }
 
     /// <summary>
     // IENumerator allows for this function to pause before being execute
     // in this case we want out waves to spawn incrementally
     // On top of this function running incrementally
     /// </summary>
     /// <returns></returns>
     IEnumerator SpawnWave()
     {
         PlayerStats.Waves++;
       
 
         Wave wave = waves[waveIndex];
         for (int i = 0; i < wave.count; i++)
         {
 
             SpawnEnemy(wave.enemy);
             // the amount of time the function will pause given the IENumberator
             yield return new WaitForSeconds(0.5f);
         }
 
         waveIndex++;
     }
 
     void SpawnEnemy(GameObject enemy)
     {
         Instantiate(enemy, spawnPoint.transform.position, spawnPoint.transform.rotation);
 
         EnemiesAlive++;
        
     }
 }
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

134 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

script countdown 2 Answers

Immortal enemies when reanimated, or pooled game objects re-activated do not respond to collisions? 1 Answer

Activate objects in array based on value 3 Answers

Activate Game object when in Camera view and deactivate when out of camera view. 2 Answers

How to activate a specific script in a Prefab. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges