Skip to content

Instantly share code, notes, and snippets.

@Xiaoy312

Xiaoy312/code fix.cs Secret

Created May 16, 2016
Embed
What would you like to do?
#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

This comment has been minimized.

Copy link

@StephenG453 StephenG453 commented May 16, 2016

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

This comment has been minimized.

Copy link
Owner Author

@Xiaoy312 Xiaoy312 commented May 17, 2016

  • 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

This comment has been minimized.

Copy link
Owner Author

@Xiaoy312 Xiaoy312 commented May 17, 2016

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

This comment has been minimized.

Copy link

@StephenG453 StephenG453 commented May 18, 2016

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