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 /
This question was closed Mar 13, 2020 at 10:01 PM by tormentoarmagedoom for the following reason:

Too subjective and argumentative

avatar image
-1
Question by arata27 · Mar 13, 2020 at 07:49 AM · next leveleliminate

,How do I code a script that player need to destroy all of enemies in all waves to move to the next scene.

Hi I'm facing the problem of making a script that the player need to kill all of the enemies in in every waves before the player could automatic move to the next scene. Since the code that I have I could only kill one of the enemy and it move to the next scene instead of need to kill all of enemies. So how do I create the connection between the SpawnManager so that the player can kill all of the enemy in the waves and then progress to the next level instead on kill one and progress.

GameController

 [SerializeField] Button newGameButton = default;
 [SerializeField] Button quitGameButton = default;
 [SerializeField] Canvas theMainMenu = default;
 public static GameController gameController;
 public int playerHP;
 public int playerScore;

   
 private void Awake()
 {
     if (gameController == null)
     {
         DontDestroyOnLoad(gameObject);
         gameController = this;
     }
     else if (gameController != this)
     {
         Destroy(gameController);
     }

     newGameButton.onClick.AddListener(StartNewGame);
     quitGameButton.onClick.AddListener(QuitGame);
 }


 private void StartNewGame()
 {
     theMainMenu.gameObject.SetActive(false);
     SceneManager.LoadScene(1);

 }

 private void QuitGame()
 {
     Application.Quit();

if (UNITY_EDITOR)

    UnityEditor.EditorApplication.isPlaying = false;
     return;

endif

}

 public void RestartLevel()
 {
     playerHP = 100;
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

 }

 public void LoadLevel()
 {
    
     int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;

     if (currentSceneIndex == 3)
         currentSceneIndex = 0;
     else
         currentSceneIndex++;

     SceneManager.LoadScene(currentSceneIndex);
 }

}


SpawnManager

 [SerializeField] int numberOfEnemies;  
 private GameObject ourPlayer;
 private PlayerHud ourHudScript;
 public GameObject ourEnemy;
 
 private int score = 0;  //beginning score 
 public int waveCount = 1; // beginning wave


 List<GameObject> enemies;  // list to hold enemies
 public int deadEnemy = 0;  // list to hold dead enemies
 [SerializeField] List<GameObject> enemyStart = default;


 void Start()
 {
     //Get (or find) a reference to the player so we can tell the HUD how many enemies are needed to progress the wave
     ourPlayer = GameObject.FindGameObjectWithTag("Player");
     ourHudScript = ourPlayer.GetComponentInChildren<PlayerHud>();

     enemies = new List<GameObject>(); //create list to hold enemies and instantiate them into the scene upon start


     spawnEnemies(numberOfEnemies);  //spawn enemies based on the number of enemies

     ourHudScript.ShowScore(score, numberOfEnemies);  //present score to hud on start
     ourHudScript.ShowWave(waveCount);  //present waveCount to HUD


 }
 public void RemoveEnemy(GameObject deadEnemy)  //remove enemies if destroyed and increment the kill counter
 {
     score++;  //increment score
     Destroy(deadEnemy);  //destroy enemy
     enemies.Remove(deadEnemy);  //bring out your dead
     //this.deadEnemy++;  //specify the dead to remove

     if (score == numberOfEnemies)
         waveCount++;

     
     ourHudScript.ShowScore(score, numberOfEnemies);  //show score on screen
     ManageWaves();  //manage the waves
 }

 private void ManageWaves()  //wave manager
 {
     

     if (deadEnemy == 3)  //if the dead enemies = 3
     {
         waveCount++;  //increase the wave count by 1
         numberOfEnemies = (4); //set the text for number of enemies to kill to 4
         spawnEnemies(4);  //increase the starting enemy number (3) by 1.. to (4)
         score = 0;  //reset current score to 0
         ourHudScript.ShowWave(waveCount);  //display the wave count

     }
     else if (deadEnemy == 7)  //if the dead enemies = 7
     {
         waveCount++;  //increase the wave count by 1
         numberOfEnemies = (5);  //set the text for number of enemies to kill to 5
         spawnEnemies(5);  //increase the starting enemy number of the previous itteration (4) by 1.. to (5)
         score = 0;  //reset current score to 0
         ourHudScript.ShowWave(waveCount);  //display the wave count
     }
     else if (deadEnemy == 12)
     {
         //display you win text  winText.text
     }

     GameController.gameController.LoadLevel();
 }

 private void spawnEnemies(int numEnemy)  //spawn enemy army
 {
     for (int i = 0; i < numEnemy; i++)  //iterate enemy count by 1 each time
     {
         enemies.Add(Instantiate(ourEnemy, enemyStart[i].transform.position, enemyStart[i].transform.rotation));  //instantiate enemies and set their direction
     }
 }

}


PlayerHud

 public Canvas ourCanvas;
 public Text ammoText;
 public Text useText;
 public Text lootText;
 public Text healthText;
 public Image screenOverlay;
 public string displayText = "";
 public Text waveText;
 public Text scoreText;
 public SpawnManager ourSM;

 private PlayerController ourPC;


 //set items that should function on start
 void Start()
 {       
     ourPC = GetComponentInParent<PlayerController>();
     //ourSM = GetComponentInParent<SpawnManager>();
     useText.gameObject.SetActive(false);
     lootText.gameObject.SetActive(false);
     screenOverlay.gameObject.SetActive(false);

 }

 
 void Update()
 {
     ammoText.text = "Ammo : " + ourPC.ammoCount + " / 100";  //update ammo amount for player
     healthText.text = "Health : " + GameController.gameController.playerHP;  //update health for player
     waveText.text = "Wave : " + ourSM;

     if (ourPC.showUse)  //display usable items
         ShowTheUseTip(true);
     else
         ShowTheUseTip(false);

     if (ourPC.isDead)  //display red screen of death if player is dead
     {
         screenOverlay.color = new Vector4(1f, 0f, 0f, 0.5f);
         screenOverlay.gameObject.SetActive(true);
     }
     else  //otherwise set the activity of the screen overlay to !active
     {

         screenOverlay.gameObject.SetActive(false);
     }
 }

 private void ShowTheUseTip(bool value)  //is the object active yes/no
 {
     useText.text = displayText;  //display text
     useText.gameObject.SetActive(value);  //set text as active

 }

 public void DisplayTheLoot(string theText)  //display the loot text
 {
     StartCoroutine(DisplayLoot(theText));
 }

 IEnumerator DisplayLoot(string theText)  //loot the loot
 {
     lootText.text = theText;  //link to loot text

     lootText.gameObject.SetActive(true);  //set text as active
     yield return new WaitForSeconds(5f);  //
     lootText.gameObject.SetActive(false); //make text disappear after xx sec

 }
 public void ShowScore(int score, int outOf)  //update the scoreText when an enemy is removed
 {
     scoreText.text = "Score : " + score.ToString() + "/" + outOf.ToString();  //set the score information from the spawn manager

 }
 public void ShowWave(int wave)  //update the scoreText when an enemy is removed
 {
     waveText.text = "Wave : " + wave.ToString() + "/" + "3";  //set the score information from the wave manager inside the wave manager

 }

}

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

  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Mar 13, 2020 at 10:01 PM

FAQ :

What are the guidelines for writing good questions?

We want Unity Answers to become a comprehensive database of questions and answers related to Unity. When you ask your questions, it can be helpful to keep a few things in mind:

Don't write things that will be irrelevant in a few days. Writing that "This is urgent!" will probably not get you faster answers, but it may make people frown at your question.

Some reasons for getting a post rejected:

There exists duplicate questions with answers if you were to do a search, either on Answers or on the Forum or on Unity's tutorials

Your question isn't specific enough: asking for a script, asking multiple questions in one post or asking a question that could be either subjective or require extensive discussion


Its like you downloaded a full game, came here to UA and ask for people to modify it to get what you want.

Bye Bye! post closed.

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

Follow this Question

Answers Answers and Comments

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

Use a string to call a class 2 Answers

How to, with a button, switch to another level when all items are collected? 1 Answer

how to make level go to next 1 Answer

How to have a Next Level and Game Over pop up in scene please help! 1 Answer

Hi! I need a JavaScript that allows me to go to the next level after I have reached a condition. 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