An object reference is required to access non-static member

by detdimples   Last Updated November 14, 2017 14:13 PM

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()
    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") {
Tags : unity scripting

Related Questions

How does Unity call "update()" in the scripts?

Updated April 23, 2015 21:05 PM

Instantiating prefabs dynamically in script

Updated April 08, 2015 18:05 PM

DontDestroyOnLoad() doesn't work in Unity

Updated April 14, 2015 20:05 PM

Questions about scaling in a 2d game in unity

Updated April 20, 2015 22:05 PM

Is it safe StringToHash() to use in Unity?

Updated May 17, 2015 21:05 PM