-
-
Save Xiaoy312/f600c48d814982bccac1ed80586efbff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region fix #1 | |
// ObstacleSpawnerBase: change IEnumerable<WaitForSeconds> to IEnumerable | |
protected abstract IEnumerable SpawnObstaclesImpl(); | |
#endregion | |
#region fix #2 | |
// ObstacleSpawnerBase: change IEnumerable<WaitForSeconds> to IEnumerator | |
protected abstract IEnumerator SpawnObstaclesImpl(); | |
// ObstacleSpawnerBase.SpawnObstacles: | |
IEnumerator SpawnObstacles() | |
{ | |
yield return new WaitForSeconds(obstacle.startGameWait); | |
while (true) | |
{ | |
var etor = SpawnObstaclesImpl(); | |
while (etor.MoveNext()) | |
yield return new WaitForSeconds(obstacle.spawnWait); | |
yield return new WaitForSeconds(obstacle.waveSpawnWait); | |
} | |
} | |
// in the "core implementation": change IEnumerable to IEnumerator | |
#endregion |
And, don't nest these concrete classes
under another class. Especially not in a class that inherits MonoBehaviour
, as this doesn't make sense at all.
Sorry I was out of town today and didn't have my computer on me. So for clarification, the classes in the ObstacleSpawnerBase script do NOT have to be abstract? And the image under your sentence "So either group them under a single file:", the C# script name would be entitled "ObstacleSpawners"? And what do the "{ /.../ }" mean? Sorry I keep dragging this on I just want to learn as much as possible :) @Xiaoy312
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One last thing.. should those classes in the ObstacleSpawnerBase script be Abstract?
Non, it shouldn't be.
should I have a script entitle 'CoreImplementation" that envelops all of those classes in my other script
Generally, you should have 1 class(or, script if you like) per file. However, some exceptions can be made. If a or many small classes are closely tied/related to an another class, like we have here. You can choose to put them together.
So either group them under a single file:
Or, each class in each own file/script.