Tyler Hayes | Game Programmer

Turn System | System Programmer

Tools Used: Unity, C#

Unlike most of the other work on here, this is purely code. Around the start of my Capstone project (coming out soon on steam!), I had to make a turn system for our turn-based game. As the heart of the game, the turn system had to be simple, so it’s easy to debug, and scalable, so we can add more to it if needed. I managed to fulfill both of these conditions in an elegant solution.

This turn system came about when I learned about Delegate.GetInvocationList(). All Delegate.GetInvocationList() does is give you a list of all of the functions that are subscribed to the named Action. Once I learned about this, the structure of the turn system slowly formed in my head. Here’s an outline of it:

    1. Once the turn system goes to a new phase, it sends out an Action to tell any number of other scripts that the turn system has reached that phase.
    2. The turn system then stores the number of scripts that were subscribed to the event.
    3. The turn system waits until it hears back from other scripts the same number of times that it stored earlier
    4. It then automatically moves onto the next phase of the turn

This approach ends up with a system that is fully scalable – any number of scripts and functions can subscribe to the different phases of the turn and the turn system will adapt to it!

Ready to Create?