Skip to content

Instantly share code, notes, and snippets.

@Xiaoy312
Created May 16, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xiaoy312/f600c48d814982bccac1ed80586efbff to your computer and use it in GitHub Desktop.
Save Xiaoy312/f600c48d814982bccac1ed80586efbff to your computer and use it in GitHub Desktop.
#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
@StephenG453
Copy link

I did all of that and I changed "using System.Collections.Generic" to just "System.Collections" and all of the errors went away and my game can play! One last thing.. should those classes in the ObstacleSpawnerBase script be Abstract? And should I have a script entitle 'CoreImplementation" that envelops all of those classes in my other script? Screenshots below with comments of what I am asking:
debug_2
debug_3

@Xiaoy312
Copy link
Author

  • One last thing.. should those classes in the ObstacleSpawnerBase script be Abstract?

    The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. Members marked as abstract, or included in an abstract class, must be implemented by classes that derive from the abstract class.

    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:

    // ObstacleSpawners.cs
    public abstract class ObstacleSpawnerBase : MonoBehaviour { /*...*/ }
    
    public class HammerSpawner : ObstacleSpawnerBase  { /*...*/ }
    public class RoadBlockSpawner : ObstacleSpawnerBase  { /*...*/ }
    public class ConeSpawner : ObstacleSpawnerBase  { /*...*/ }
    public class BarrelSpawner : ObstacleSpawnerBase  { /*...*/ }
    

Or, each class in each own file/script.

@Xiaoy312
Copy link
Author

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.

@StephenG453
Copy link

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