Move to the next level once all with "enemy" are dead with tag
Hey all I am new to programming and Scripting so using what I know I created this script
using UnityEngine;
using System.Collections;
public class NextLevel : MonoBehaviour {
public class GameController : MonoBehaviour
{
public int enemy;
void Update()
{
enemy=gameObject.FindGameObjectsWithTag("Enemy");
//enem2=GameObject.FindGameObjectsWithTag("Enemy2")
if(enemy==0) // this is if i needed more // && (enemy2==0)
{
Application.LoadLevel("EndTitle");
}
}
}
}
But I keep getting an error "error cs0176 static member" was wondering how I could fix this should I try making it private int or is there a better way to check if all enemies are dead. Thanks in advance
Answer by mybluesock · May 08, 2017 at 07:14 PM
FindGameObjectsWithTag() returns an array of all the gameObjects, not an integer. So instead of if(enemy==0)
, you could use if(enemy.Length==0)
.
Answer by CallumWB · May 09, 2017 at 10:25 AM
@mybluesock I will give that ago so where I have my if statement I should change it to enemy.Length and it should be picking them up.
Your answer
Follow this Question
Related Questions
Moving to Next Level on collision 1 Answer
Help with Non-Linear Levels 1 Answer
AddForce to object using OnCollisionEnter via a pre-existing AddForce? 0 Answers
Tagging Terrain Textures 0 Answers
Change Enemy Direction 1 Answer