Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by hal0000 · May 16, 2018 at 08:40 PM · scene-loadingtime.deltatimescene-changerestarttimer countdown

Somethings Wrong After Restarting Scene

Hi,

I am making a Tower Defense Game and after pressing Restart Button, sometimes restarting well, sometimes not restarting properly i need help.

This is my restart code:

     public void Toggle()
     {
         ui.SetActive(!ui.activeSelf);
         topUI.SetActive(!topUI.activeSelf);
         if (ui.activeSelf)
         {
 
             Time.timeScale = 0f;
         }
         else
         {
             Time.timeScale = 1f;
         }
     }
     public void retry()
     {
         scenefader.FadeTo((SceneManager.GetActiveScene().name));
         Toggle();
     }

and i believe this is corrupt script:

 public float timeBetweenWaves = 5f;
 public float countdown = 5f;

 private int waveIndex = 0;
 public Text waveCountDownText;
 void Update()
 {
     if(EnemiesAlive > 0)
     {
         return; 
     }
     if (countdown <= 0f && EnemiesAlive<=0)
     {
         StartCoroutine(SpawnWave());
         countdown = timeBetweenWaves;
         return;
     }
     countdown -= Time.deltaTime;
     countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
     waveCountDownText.text =Mathf.Round(countdown).ToString();
     waveCountDownText.text = string.Format(" {0:00.00}", countdown);
 }


    IEnumerator SpawnWave()
     {
     PlayerStats.Rounds++;
     WaveInfo wave = waves[waveIndex];
         for (int i = 0; i < wave.count; i++)
         {
             SpawnEnemy(wave.enemy);
             yield return new WaitForSeconds(1f / wave.rate);
         }
             waveIndex++;
         if (waveIndex == waves.Length)
         {
         Debug.Log("level won");
         this.enabled = false;
         }

 }

alt text

You can see on top middle of screen time countdowning and when it's equal to 0 wave starting but sometimes after restarting the scene i don't know why time is not starting to count down and not showing it on text too. You can see on Second Picture time is not showing and wave is won't starting.

alt text

adsızzzzzzzzzzzzzzzzzz.png (259.3 kB)
adsızz2222222222222222222zz.png (242.3 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hal0000 · May 16, 2018 at 10:11 PM

i fixed by debugging i changed my code to this :

      void Start()
     {
         countdown = 5f;
         waveCountDownText.text = Mathf.Round(countdown).ToString();
         EnemiesAlive = 0;
     }
     void Update()
     {
         if (EnemiesAlive > 0)
         {
             return;
         }
         else
         {
             if (countdown <= 0f)
             {
                 StartCoroutine(SpawnWave());
                 countdown = timeBetweenWaves;
                 return;
             }
             else
             {
                 countdown -= Time.deltaTime;
                 countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
                 waveCountDownText.text = Mathf.Round(countdown).ToString();
                 //waveCountDownText.text = string.Format(" {0:00.00}", countdown);
             }
         }
     }
        IEnumerator SpawnWave()
         {
         PlayerStats.Rounds++;
         WaveInfo wave = waves[waveIndex];
             for (int i = 0; i < wave.count; i++)
             {
                 SpawnEnemy(wave.enemy);
                 yield return new WaitForSeconds(1f / wave.rate);
             }
                 waveIndex++;
             if (waveIndex == waves.Length)
             {
             Debug.Log("level won");
             this.enabled = false;
             }
         }

Comment
Add comment · Share
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

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

142 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why isn't my start screen loading? 0 Answers

Build errors in unity 0 Answers

Restarted scene not working properly 0 Answers

C# Unity Main Menu Scene is Blue when played 1 Answer

multiple of same objects from DontDesroyOnLoad 0 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