Communicating between GameObjects

In any game, there are planned interactions between any components within the game. These could be as follows:

  • Physics collision tests
  • Reacting to being shot or shooting
  • Opening and closing doors
  • Triggers, switches, or traps
  • Two or more characters talking

There are several ways in which you can achieve this, and each has its own particular traits. The selection of the implementations depends on what you need to achieve. The methods are as follows:

  • Delegates
  • Events
  • Messaging

In this section, we will go through each method in detail and highlight the best uses of each.

Delegates

We encounter delegates in our everyday lives. Sometimes they are managers, sometimes they are subordinates, and they could even be the barista at your ...

Get Mastering Unity 2D Game Development - Second Edition 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.