Whenever a player is added to the game (in the form of the server instantiating a player Game Object with a
Player component), I want to provide it to every script that needs a reference; in other words, dependency injection.
I thought I’d create an
IPlayerRequester interface and have the
Player script look up all implementing scripts on the client when it’s created, but Unity has no interface-searching equivalent of
The game is multiplayer, where 1 player is the host — a client and the server — that is joined by other clients.
I’m using Mirror.
When a new client is added, the
Player script’s (that was just spawned) callback
OnStartLocalPlayer() is invoked, and so far, that’s the only way I’ve found to access the local environment.
But because this is the same
Player that I’m trying to inject into requesting scripts, I can’t just raise an event in that method, so that’s out.
What would be a good solution here?