I have a code that I want to use to change levels everytime the player kills a certain amount of enemies, but it gives me this error:
An object reference is required to access non-static member `enemyCount.nextLevelName'
Here's my script (this is attached to an empty game object)
public class enemyCount : MonoBehaviour {
public static int enemiesCount;
public int targetCount;
public string nextLevelName;
void Start()
{
enemiesCount = targetCount;
}
public static void DecreaseCount()
{
enemiesCount--;
print("Enemy Count is " + enemiesCount);
if(enemiesCount <= 0)
{
Debug.Log("Load level: " + nextLevelName);
Application.LoadLevel (nextLevelName);
}
}
}
and this is inside the bullet script
if (collision.gameObject.tag == "Enemy") {
enemyCount.DecreaseCount();
}