It’s my first game, so I would really appreciate if someone would help!
I want enemies that are spawn with enemySpawner script to move with a certain path that is generated with a method in settingPath script, however after adding this method in enemySpawner coroutine it gives me a NULLReferenceExeption:
NullReferenceException: Object reference not set to an instance of an object
EnemySpawner+d__7.MoveNext () (at Assets/Scripts/EnemySpawner.cs:45)
I can’t find the root of the problem.
Here is a pathScript that has a method SetEnemyPath that takes a GameObject as a parameter and than sets a path for this GameObject to move
Here is a enemySpawner script that has a coroutine which is spawning enemies with waves.So here I wanted every enemy in the wave to have a different path to follow.
And here is coroutine in which this method should be working, right after Instatiating enemy it should follow the path that is created by SetEnemyPath method
Use code tags. Screenshots don’t help anybody.
This is the wrong place to post, as well. Questions like this go in the Scripting subforum.
The error message in the thrown NullReferenceException means a reference to an object being used to access a member (field / property / indexer), call a method on it, etc. is not set to a valid object. That makes it impossible to go through with calling a method or getting / setting a field or property or indexer.
Look at the line number the error message points to and figure out what variable or field / property etc. might be null.
You can also use a debugger to set a breakpoint at that line and check objects being used in that context and see what is null among the things used in that line.