3
Spawning Enemies with the Prototype Pattern
In the last chapter, we dove head-first into our first design pattern – the Singleton. We talked about its strengths, weaknesses, and practical implementations with C# and Unity-specific APIs (while simultaneously trying not to vilify the poor thing). In this chapter, we’ll learn how the Prototype pattern can help you define and manage objects you want to copy while avoiding the computational overhead that comes with creating new objects (because we should all aim to be frugal programmers when it comes to memory).
The idea is to take the original object (called a – you guessed it – Prototype or prototypical instance) and return copies of it whenever needed. Think of games where procedural enemies ...
Get Learning Design Patterns with Unity now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.