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 DanTCW_Gaming · Apr 30, 2020 at 05:17 AM · playerdeath

How do I get rounds to work on a wave-based game?

This did work, but then I changed what I had as a Player to a FirstPersonController, and then health, and rounds didn't work. I had help getting health done. But now the Player won't die, and the Rounds won't go to the next number.

using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class Spawners { public GameObject go; public bool active; public Spawners(GameObject newGo, bool newBool) { go = newGo; active = newBool; } }

public class GameManager : MonoBehaviour { public GameObject panel; public delegate void RestartRounds(); public static event RestartRounds RoundComplete;

 private int health;
 private int roundsSurvived;
 private int currentRound;
 private PlayerDamage playerDamage;
 private Text panelText;

 public List<Spawners> spawner = new List<Spawners>();

 void Start()
 {
     Time.timeScale = 1;
     panel.SetActive(false);
     playerDamage = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerDamage>();
     panelText = panel.GetComponentInChildren<Text>();
     foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
     {
         if (go.name.Contains("Spawner"))
         {
             spawner.Add(new Spawners(go, true));
         }
     }
 }

 void Update()
 {
     int total = 0;
     health = playerDamage.health;
     if (health > 0)
     {
         for (int i = spawner.Count - 1; i >= 0; i--)
         {
             if (spawner[i].go.GetComponent<Spawner>().spawnsDead)
             {
                 total++;
             }
         }
         if (total == spawner.Count && roundsSurvived == currentRound)
         {
             Debug.Log("Checking if executes");
             roundsSurvived++;
             panelText.text = string.Format("Round {0} Completed", roundsSurvived);
             panel.SetActive(true);
         }

         if (roundsSurvived != currentRound && Input.GetButton("Fire2"))
         {
             currentRound = roundsSurvived;
             RoundComplete();
             panel.SetActive(false);
         }
     }
     else
     {
         if (Input.GetButton("Fire2"))
         {
             Scene current = SceneManager.GetActiveScene();
             SceneManager.LoadScene(current.name);
         }
         else
         {
             panel.SetActive(true);
             panelText.text = string.Format("Survived {0} Rounds", roundsSurvived);
             Time.timeScale = 0;
         }
     }
 }

}

there is the code for the GameManager that controls the rounds, IDK what is different between the FirstPersonController, and the Player I had.

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 Cassos · Apr 30, 2020 at 10:47 AM

use an IEnumerator that's called when you want to start the wave system.

Comment
Add comment · Show 1 · 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 DanTCW_Gaming · Apr 30, 2020 at 01:35 PM 0
Share

Where do I place it in the code, or do I make a separate script for it?

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

156 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

Related Questions

How do i make my player die? 2 Answers

How to add Player health and ability to take damage from a cube? 2 Answers

OnCollisionEnter issues 3 Answers

Death screen and going to it after character HP hits 0? 2 Answers

How to make the monster kill you? 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