Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MarvinH · Feb 26, 2021 at 04:58 PM · programmingtower defense

How to create and display a list of enemies in upcoming wave?

Hi All,

I am working on a tower defense game, I wanted a way for the player to see the enemy units in the next wave,=. So my approach was to create a gui text object, add a refference to the waveManager(I just have it assigned in the inspector for now) class which holds all of the information for each wave. The waveManager class is broken down as a collection of events, and each even is broken down as a spawn events, which is where I set the enemy types and spawn locations. The spawn info is also a collection, so I have a list within a list. I get an argument out of range error, I know that I need to iterate over both the event and spawn infos collection, but I can't figure out how to do it correctly. Are there any examples on how to display the content in a wave?

 public class WaveManager : MonoBehaviour {
 
     public List<WaveEvent> events = new List<WaveEvent>();
     public List <Text> nextWaveText; //List of enemies
     private bool isPlaying = false;
     public float waveDelay = 5f; //Used to delay the stArt of eacach wave
 
 
     public void StartWave()
     {
             isPlaying = true;
 
             if (events.Count != 0)
         {
             events[0].StartEvent();
             for (int i = 0; i < events.Count; i++)
             {
                 Debug.Log(events[i].spawnInfos[0]);
                  //   nextWaveText[i].text = events[0].spawnInfos[i].spawnedEnemyName;
                 
                  
                     
             }
              
         }
               
             else
             {
                 LevelManager.Instance.Endwave();
       
 
             }
 
        
     }
 
    private void Update()
     {
         if (!isPlaying)
             return;
 
         if(!events[0].RunEvent())
         {
                 Debug.Log("End Event");
                 events.RemoveAt(0);
                 if (events.Count == 0)
                 {
                     LevelManager.Instance.Endwave();
                 }
                 else
                     events[0].StartEvent();
 
             }
         }
     }
 
     //classs that controls what happens in a wave object
     [System.Serializable]
     public class WaveEvent
     {
         
         public float duration = 15.0f;
         public List<SpawnInfo> spawnInfos;
       //  public List<GameObject> spawnpoints;
 
         private float startTime;
 
         public void StartEvent()
         {
             startTime = Time.time;
         }
 
         public bool RunEvent()
         {
         //No duration, and nothing to spawn and i empty, end the event
             if (duration == 0.0f && spawnInfos.Count == 0)
                 return false;
             else if(Time.time - startTime > duration && duration != 0.0f)
             {
                 return false;
             }
 
             for(int i =0; i < spawnInfos.Count; i++)
             {
                 spawnInfos[i].ReadyToSpawn();
            
 
             if (spawnInfos[i].amount== 0)
                 {
                     spawnInfos.RemoveAt(i);
                 }
             }
             return true;
         }
 
         [System.Serializable]
         public class SpawnInfo{
             public int spawnPointIndex = 0; //The point at which new enemies are created
             public int spawnPrefabIndex = 0; //The type of enemy to spawn
         public string spawnedEnemyName;
             //First two called from spawn manager
             public int amount = 10;
             public float interval = 1.0f;
             private float lastTime;
         //Time betwewen each wave
 
             public float countdown = 10f;
 
 
  //Does the actual spawning
 
             public void ReadyToSpawn()
             {
                 if(Time.time - lastTime >= interval)
                 {
                 SpawnManager.Instance.Spawn(spawnPrefabIndex, spawnPointIndex);
                 amount--;
                lastTime = Time.time;
                     
                 }
 
             }
 
     }


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

Answer by MarvinH · Feb 28, 2021 at 08:20 PM

woof crickets. Is there anything I can do to make this question more clear?

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

126 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

Related Questions

Multiple Cars not working 1 Answer

What exactly is going on when I implement Update(), and other messages in MonoBehaviour 2 Answers

How to move a player automatically through a List of Waypoints? 1 Answer

Yet Another Bullet Decal Problem 0 Answers

How can i use any imported model(for example Crysis Nanosuit) instead of mecanim rigged model? 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