So I've been trying to create a multiplayer game, and with some success. Currently I have peers connecting to each other, a chat room with a couple commands, and a completely broken rest of the game.
First I followed Multiplayer tutorial 4: real-time game and created a simple "you can move around and the other player sees it" game, and it worked! I made a multiplayer thing! So everything in the project to do with the player object and multiplayer is essentially identical to the tutorial.
Anyway, after doing that I thought "the whole, [on peer connected] thing doesn't suit my game, since they're already connected in the lobby (chat room) and so it won't trigger when you go to the actual game, or more importantly, when a player dies".
So I tried something.
I disabled the normal method, because I was about to replace it elsewhere:
And then I created a different method, on the host's side, for spawning an object for each peer:
I thought a for loop would be perfect. It could cycle through each peer and assign an object to each one.
The bit on the end is the debug method of determining what object is associated with each peer.
It didn't work. On the peers' side, every object is associated with the host, because it was previously relying on [on peer connected] to get the Multiplayer.PeerID for when it was created:
Having spent about 10 hours straight trying to work out a way to fix this, I feel like I've tried everything at this point.
So, is there a proper way to do it? Have I missed something? I need to be able to create new peer objects whenever I want, but at the moment it seems like [on peer connected] is the only viable option.
Thank you so much if you have any advice!
Develop games in your browser. Powerful, performant & highly capable.