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 /
avatar image
0
Question by arashsh · Mar 15, 2020 at 05:47 AM · variableloopclassfloatreset

How Reset Variable After Loop

Hi, i have a custom class with a variable(rate) and this variable change after time, I want my variable back to default after my code looping

      public class Wave
      {
          public float rate;
      }
 public class SpawnerPool : MonoBehaviour
 {
      public Wave[] waves;
      public int nextWave;
      
     
   
     void WaveCompleted()
      {
          waveCountdown = timeBetweenWaves;
  
          if (nextWave + 1 > waves.Length - 1)
          {                
              nextWave = 0;         
              ShowTextAnimation4();
             // Reset Class Variable 
          }
          
          else
          {
              nextWave++;
          }
      }   
      
      IEnumerator SpawnWave(Wave _wave)
      {
          
           
          // Spawn
          for (int i = 0; i < _wave.count; i++)
          {
            if(SpawnGo)
            {
              if(_wave.enemyindex == 1)
              {
                SpawnEnemy(PoolObjectType.Enemy);
              }
              
              if(_wave.enemyindex == 2)
              {
                 SpawnEnemy(PoolObjectType.Enemy2);
              }
              
              if(_wave.enemyindex == 3)
              {
                 SpawnEnemy2(PoolObjectType.Enemy3);
              }
 
              if(_wave.enemyindex == 4)
              {
                 SpawnEnemy(PoolObjectType.Enemy2);
              }
               yield return new WaitForSeconds(_wave.rate);
 
              if(_wave.name == "wave1")
              {
                 if(nextDrop >= 7)
                 {
                   if(_wave.rate > 0.3f)
                   _wave.rate -=  0.07f;
                 }
              }
              if(_wave.name == "wave2")
              {
                   if(_wave.rate > 1f)
                   _wave.rate -=  0.04f;
              }
 
            }
   
          } 
 
  
          yield break;
      }

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 ShadyProductions · Mar 15, 2020 at 08:33 AM

Instead of adjusting the rate, you could keep 2 variables on the wave instead and only adjust the other variable based on the rate?

Comment
Add comment · Show 2 · 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
avatar image arashsh · Mar 15, 2020 at 08:46 AM 0
Share

2 variables? i'm not sure, can you give an example?

avatar image arashsh · Mar 15, 2020 at 09:46 AM 0
Share

thank man, this work i appreciate you:)

public float rate; public float rate2;

 IEnumerator SpawnWave(Wave _wave)
      {
 
          state = SpawnState.SPAWNING;
          if(SpawnGo == false)
          {
            yield break; 
          }
           
          // Spawn
          for (int i = 0; i < _wave.count; i++)
          {
            if(SpawnGo)
            {
              if(_wave.enemyindex == 1)
              {
                SpawnEnemy(PoolObjectType.Enemy);
              }
              
              if(_wave.enemyindex == 2)
              {
                 SpawnEnemy(PoolObjectType.Enemy2);
              }
              
              if(_wave.enemyindex == 3)
              {
                 SpawnEnemy2(PoolObjectType.Enemy3);
              }
 
              if(_wave.enemyindex == 4)
              {
                 SpawnEnemy(PoolObjectType.Enemy2);
              }
               yield return new WaitForSeconds(_wave.rate);
 
              if(_wave.name == "wave1")
              {
                 if(nextDrop >= 7)
                 {
                   if(_wave.rate > 0.3f)
                   _wave.rate -=  0.07f;
                 }
              }
              if(_wave.name == "wave2")
              {
                   if(_wave.rate > 1f)
                   _wave.rate -=  0.04f;
              }
         
              
            }
       
              
          } 
            
          state = SpawnState.WAITING;
          // two variable 
          _wave.rate = _wave.rate2;
  
          yield break;
      }

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

130 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

Related Questions

how to reset a float var 2 Answers

How may i get a variable from another script onto my wanted Script? 1 Answer

Unity setting SerializedProperty.prefabOverride incorrectly 2 Answers

Share Public Classes 1 Answer

public class variable in inspector like other components? 1 Answer


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