Hi guys, I posted a Question but it has been some hours now, (10) and a mod has not seen it. I was told by somebody to post it on here too. here is my question. Copy and Paste!
I am trying to work on a script so when the ‘Player’ is destroyed a level will load. The Script is working but it loads the level instantly. It does not wait for the play to die.
using UnityEngine; using System.Collections;
public class GameOver : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Also I should say that the only way that the player can be destroyed is by the collider with the enemy block. I don’t know why I wrote that script as it was but hey its 3:30AM! =D
Also how would one write a script to make it so when all the Objects with a certain tag has been Destroyed it loads a new level?
The documentation of GameObject.FindGameObjectsWithTag says “Returns a list of active GameObjects tagged tag. Returns null if no GameObject was found.”, so I would check for a null pointer before accessing the “Length” value. Actually, just checking that it returns null to load the level would be enough no?
As for you current code, you’re checking with “less or equal to 1” so it’s normal that even when the player is still alive, the condition is true.