Cs0120

Hello.

I’ve tried to follow along with this lecture, but Intellisense wouldn’t fill in the WaveConfig methods and when I did, I got the error CS0120, “An object reference is required for the nonstatic field, method, or property ‘member’.”

What should I do? I cannot move on to the actual for loop challenge because of this.

private IEnumerator SpawnAllEnemiesInWave(WaveConfig config)
    {
        Instantiate(WaveConfig.GetEnemyPrefab(), WaveConfig.GetWaypoints()[0].transform.position, Quaternion.identity);
 }

Thanks.

Hi,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

For example, is your variable named WaveConfig or waveConfig?


See also:

you probably forgot the keyword static on the WaveConfig code, like on the GetEnemyPrefab() method or GetWaypoints() method)

I’ve checked both my code on WaveConfig and the WaveConfig video and it doesn’t mention adding the static keyword to the code.

The WaveConfig file has the same name as the WaveConfig I’m using for enemySpawner.cs.

instead of

WaveConfig.GetEnemyPrefab()

should it not be

config.GetEnemyPrefab()

If you use WaveConfig.someMethod(), it means you’re calling the class itself (and thus need the keyword static). If you intend on calling the instance itself, just use the instance name (config in your case), so config.someMethod()

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms