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 justinkatic · Oct 05, 2017 at 04:58 AM · guiguitextnewbiedisplaywaves

adding wave number to HUD

Using a script from a tutorial I found on YouTube by Brackeys and its just spawning enemies and I select which enemies and how many per wave. problem is I cant work out how to add the wave name to my HUD tried so many different options and none of it seems to be working. need the _wave.name displayed in HUD. Ignore all the comments that's just me trying to understand everything since very new to coding :D help would definitely make my day thanks.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class WaveSpawner : MonoBehaviour {

 public enum SpawnState { SPAWNING, WAITING, COUNTING };

 [System.Serializable]                // allows us to change values inside of inspector
 public class Wave
 {
     public string name;                //name of wave
     public Transform enemy;            // refrence to prehab we want to initiate
     public int count;                // amount of waves
     public float rate;                // spawn rate
 }

 public Wave[] waves;
 private int nextWave = 0;
 public int NextWave
 {
     get { return nextWave + 1; }
 }

 public Transform[] spawnPoints;

 public float timeBetweenWaves = 5f;            //time between waves 5 seconds
 private float waveCountdown;                
 public float WaveCountdown
 {
     get { return waveCountdown; }
 }

 private float searchCountdown = 1f;            //instantiate to check if all enemy are dead every 1 second instead of every frame

 private SpawnState state = SpawnState.COUNTING;
 public SpawnState State
 {
     get { return state; }
 }

 void Start()
 {
     if (spawnPoints.Length == 0)                                
     {
         Debug.LogError("No spawn points referenced.");                        // checks if a spawn point of refrenced
     }

     waveCountdown = timeBetweenWaves;                                        //how long till next wave starts default 5seconds
 }

 void Update()
 {
     if (state == SpawnState.WAITING)                                        //checks if enimies are still alive
     {
         if (!EnemyIsAlive())
         {
             WaveCompleted();                                                // if all enimies dead start next wave
         }
         else
         {
             return;                                                            // if enemies still alive return till all enimies dead
         }
     }

     if (waveCountdown <= 0)                                                    //if <=0 then start check if spawning of not start spawning then else
     {
         if (state != SpawnState.SPAWNING)    
         {
             StartCoroutine( SpawnWave ( waves[nextWave] ) );                //start spawning wave
         }
     }
     else
     {
         waveCountdown -= Time.deltaTime;                                    //makes countdown relevent to time and not frames per second
     }
 }

 void WaveCompleted()
 {
     Debug.Log("Wave Completed!");

     state = SpawnState.COUNTING;
     waveCountdown = timeBetweenWaves;                                        

     if (nextWave + 1 > waves.Length - 1)                                    // if no more waves start wave 1 again looping
     {
         nextWave = 0;
         Debug.Log("ALL WAVES COMPLETE! Looping...");                        // if final wave not completed add 1 wave
     }
     else
     {
         nextWave++;                                                            //increases wave by 1
     }
 }

 bool EnemyIsAlive()                                                        
 {
     searchCountdown -= Time.deltaTime;                                    
     if (searchCountdown <= 0f)
     {
         searchCountdown = 1f;                                            //check if all enemy are dead every 1 second instead of every frame
         if (GameObject.FindGameObjectWithTag("Gooba") == null)            //checks if all enimies with the player tag enemy are alive or dead
         {
             return false;                                                // if enemy alive repeat step till enemies are dead check this every 1 second
         }
     }
     return true;                                                        // if all enemy with tag enemy are dead then return true
 }

 IEnumerator SpawnWave(Wave _wave)
 {
     Debug.Log("Spawning Wave: " + _wave.name);
     state = SpawnState.SPAWNING;                            //spawns enimes

     for (int i = 0; i < _wave.count; i++)                    // = number of enimies we want to spawn
     {
         SpawnEnemy(_wave.enemy);                            //waits for player to finish killing enimies
         yield return new WaitForSeconds( 1f/_wave.rate );    //how long we want to wait 1 / rate untill we have number of enimies we want to spawn
     }

     state = SpawnState.WAITING;

     yield break;
 }

 void SpawnEnemy(Transform _enemy)
 {
     Debug.Log("Spawning Enemy: " + _enemy.name);

     Transform _sp = spawnPoints[ Random.Range (0, spawnPoints.Length) ];        //chooses a random spawn point 
     Instantiate(_enemy, _sp.position, _sp.rotation);
 }

}

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

123 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

Related Questions

How to display EULA from Doc in Unity? 0 Answers

Problem Displaying Score on GUI text 0 Answers

Displaying varying text 1 Answer

GUI Overlay Display 0 Answers

Simple text GUI 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