Solution

Now that we have found a solution that offers a standard interface to our game's scene entities and encapsulates them, we still need to maintain a list. Games are dynamic software; entities explode and spawn in a matter of seconds, manually managing a list of objects is error-prone.

But, if we had a common type for all our game's objects, then it will be easy for us to dynamically maintain a list of entities, and walk through it at every frame. If we have a container that holds all our game's objects, such as a scene, then we could iterate through it to find all the objects of a specific type, and call their Update() method.

That's mostly what MonoBehaviour is in Unity; it offers a common parent type for objects that are in a scene ...

Get Hands-On Game Development Patterns with Unity 2019 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.