Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | BadGamer |
Trying to figure out how to best “connect” two parts of a game I am making. To illustrate just imagine one scene we call “Inventory” and another scene we call “Coin”. These scenes are entirely unrelated and are being used in a “World” scene. The “Coins” are being instanced.
The player wants to pick up a Coin. Before being able to do this the Inventory needs to be checked and only if there is enough room the Coin can be picked up.
The idea is that a Coin needs to emit a signal telling the Inventory; “Hey, I want to be picked up, is this alright?” and then the Inventory responds with yet another signal: “Yes, that is alright”.
However for this to work the inventory needs to connect to every single coin and this requires it to be aware (in some way) of all coins.
I don’t want the Inventory system to be aware of all Coins in the World.
How can I make those Coins communicate with the Inventory? And keep everything separated.
Do I need to add another layer, for example “Coin Manager” and let it handle the communication?
Basically I want to avoid code like : for each coin: each.connect(foobar) inside my inventory.
Or am I missing something obvious?