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 andreyazbyn · Oct 09, 2015 at 03:15 PM · c#enemyenemy spawnwaves

wave spawner difficulty increase

there's the script

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class WaveSpawner : MonoBehaviour {
 
     public enum SpawnState { Spawning, waiting, counting};
     [System.Serializable]
     public class Wave {
         public string name;
         public Transform enemy;
         public int count;
         public float rate;
     }
    
  
    public List<Wave> waves = new List<Wave>();
     private int nextWave = 0;
     public Transform[] spawnPoints;
 
     private SpawnState state = SpawnState.counting;
     public float timeBetweenWaves = 5f;
     public float waveCountdown;
 
     private float searchCountdown = 1f;
     public Transform normalEnemy;
 
     public int currentCount;
     public float currentRate;
 
     void Start() {
        waveCountdown = timeBetweenWaves;
         currentCount = 2;
         currentRate = 3;
 
     }
     void Update() {
         if (state == SpawnState.waiting) {
             if (EnemyIsAlive() == false)
             {
                 WaveCompleted();
             }
             else {
                 return;
             }
         }
 
         if (waveCountdown <= 0)
         {
             if (state != SpawnState.Spawning)
             {
                 StartCoroutine(SpawnWave(waves[nextWave]));
 
             }
         }
         else
         {
             waveCountdown -= Time.deltaTime;
         }
         
     }
     void WaveCompleted() {
     
         state = SpawnState.counting;
         waveCountdown = timeBetweenWaves;
         //TODO add more waves
       //  if (nextWave + 1 > waves.Count - 1)
        // {
             currentCount += 2;
             CreateWave(normalEnemy, currentCount, currentRate);
           
         //     Debug.Log("All Waves Complete");
         //}
        
             nextWave++;
         
     }
 
     private void CreateWave(Transform Enemy, int Count, float rate)
     {
         Wave wave = new Wave();
         currentCount = wave.count;
         currentRate = wave.rate;
         wave.name = "autoGenerated Wave";
         wave.count = Count;
         wave.rate = rate;
         wave.enemy = Enemy;
         waves.Add(wave);
      
         
 }
     bool EnemyIsAlive() {
 
         searchCountdown -= Time.deltaTime;
         if (searchCountdown <= 0f)
         {
             searchCountdown = 1f;
             if (GameObject.FindGameObjectWithTag("Enemy") == null)
             {
               
                 return false;
             }
         }
         return true;
     }
 
     IEnumerator SpawnWave(Wave _wave) {
 
         state = SpawnState.Spawning;
       //  currentCount = _wave.count;
         //currentRate = _wave.rate;
 
         for (int i = 0; i < _wave.count; i++) {
             SpawnEnemy(_wave.enemy);
             
             yield return new WaitForSeconds(1 / _wave.rate);
         }
 
         state = SpawnState.waiting;
         yield break;
     }
 
     void SpawnEnemy(Transform _enemy) {
         Transform _sp = spawnPoints[Random.Range(0, spawnPoints.Length)];
         Instantiate(_enemy, _sp.position, _sp.rotation);
     }
 }
 

why doesn't it work?

Comment
Add comment · Show 2
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 meat5000 ♦ · Oct 09, 2015 at 03:24 PM 0
Share

Why do you think it doesnt work?

Whats broken about it?

avatar image Jessespike · Oct 09, 2015 at 03:31 PM 1
Share

What's the problem? The enemies don't spawn with increasing difficulty? There's no difficulty variable. You're not clear in your question. Unless you mean, difficulty is the actual number of enemies spawned. $$anonymous$$aybe has something to do with resetting currentCount everytime you spawn a wave.

      Wave wave = new Wave();
      currentCount = wave.count;     // <-- is this intended?
      currentRate = wave.rate;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andreyazbyn · Oct 10, 2015 at 06:47 AM

i found the problem these two lines

  currentCount = wave.count;     
       currentRate = wave.rate;

after removing them everything works fine

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawned enemy walk from right to left destroying turrets. 0 Answers

Survival Shooter Spawn Enemies in Waves? 0 Answers

How to instantiate the whole object with script attached to it ? 0 Answers

How To Add Multiple Objects To My Object Pooler? 1 Answer

Score counter not working properly. 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