- Home /
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.
Answer by Cassos · Apr 30, 2020 at 10:47 AM
use an IEnumerator that's called when you want to start the wave system.
Where do I place it in the code, or do I make a separate script for it?
Your answer
Follow this Question
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