If in doubt, whip a List out.
Did you know that you can highlight a group of GameObjects and then drop them into an array that has been exposed to the Inspector?
I did not know that.
You can also clear an Array by setting the index to 0. Just, FYI.
Then this happened:
So I stumbled on this gem a couple days ago by accident when I renamed the script in the Editor before renaming the class in the Script. Here’s the process:
- Rename the Script in the editor. This preserves links to the script on GameObjects.
- Highlight the name of the class in the Script and press CMD-R to rename the class and all of its references in other scripts.
At the start of 128 I decided to try to to anticipate the direction of the instruction so I chose to use Invoke. My solution to the renaming issue for Invoke has been to declare a constant string alongside the method I would use. I used a recursive strategy calling Invoke each time the transform is updated but not calling it when nextWaypoint exceeds the number of Waypoints in the List.
Obviously the coroutine method is superior to using recursive calls to Invoke if only because coroutines support easy refactoring.
Starting and Ending Waypoints
Where should the starting and ending waypoints be set?
I have to be honest in that I sat here for a couple minutes puzzling over the CubeEditor hint because my first thought was to set them in the Pathfinder script. So I did that and immediately realized that the color doesn’t update. So that didn’t work. We could expose the Pathfinder to run in the editor but I already know that’s not ok. Editor scripts should be removable at runtime. Therefore, the code goes into the CubeEditor.
So I started by defining two booleans and then realized that would mean that a cube could be both the start or the end point. Then I thought “well, it could also be neither the start or the end point. Naturally, this means we should use an enumeration. I decided the default state would be passing through and I set up the default startingColor and endingColor as private member fields.
Then on Update I check the type of the waypoint and set the top color appropriately. Run the program and it throws an error:
So probably not a completely acceptable solution.