Thank you. That’s much better!
Since waveConfig is undefined before the SetWaveConfig method, does Unity wait to execute the Start method until waveConfig is defined?
By default, no program ever waits for anything. It gets executed and that’s it. You have to write asynchronous code to wait for data to be returned but we do not cover that in this course.
So the question is: In what order do the methods get executed? Add Debug.Logs with Time.frameCount
and meaningful messages to your code. Run your game and check your console. I’m sure when you read the messages, you’ll immediately know what’s going on here.
transform.position = wayPoints[waypointIndex].transform.position; //enemy starts at the first waypoint
To be more precise: The enemy starts at the waypoint at index waypointIndex
given the index is within the range of the array and if the element at that position is not null
. If the enemy starts at the first waypoint, the condition is true only if the waypointsIndex
points to the correct index to which the first waypoint was assigned.
//This method is meant to set this class’s WaveConfig scriptable object to the same one being used by the Spawner.
To this instance’s WaceConfig object. In C#, there is a big difference between classes and instances. Classes are basically blueprints. Instances are the actual objects.
//“this” refers to the “waveConfig” belonging to the class EnemyPathing
To this instance of the EnemyPathing class. If it referred to the class, all EnemyPathing instances would get affected if you change the this.waveConfig
variable. The non-static variables at the top of your class are called instance members.