- Home /
Unity Multiplayer RPC + iOS Game Center?
Hello,
I'm currently working on a multiplayer game in Unity for iOS devices. Currently, to connect the clients to the host, you have to type in the hosts IP address, or use a master server look up.
As this is more of a research and development project, I want to be able to use Apple's Game Center functionality. I've purchased Prime31's plugins for the Game Center (plus the multiplayer plugin).
My main question is how do I actually connect the players to my game? After looking through the demo scenes and documentations, its not really clear on how I 'Spawn' a player into the scene. Right now, for my IP connections, I'm using RPC to initiate the players.
I was thinking that once a player is connected via GC, could I then pass the hosts IP address and then connect in the formal Unity manor? But then again, whats the point as the client is already connected to the host via GC.
Or do I just use Prime31's 'sendMessageToPeers' which will then initiate an RPC of the 'Spawn'?
I mean, once a player is connected via GC, can I then just use my standard RPC networking system that I've built? Or do I have to build on top of that specifically for Prime31's GC plugin to synchronies my game?
Thanks.
you don't need RPC networking system, use only GameCenter$$anonymous$$ultiplayerBinding.send$$anonymous$$essageToAllPeers(...) or/and GameCenter$$anonymous$$ultiplayerBinding.sendRaw$$anonymous$$essageToAllPeers(...), then parse the message to spawn gameObjects and other game play actions
If I do use the GameCenter, how do I deter$$anonymous$$e who's player 1, and who's player 2? Because initially, they both think they are player 1. They way I do this in Unity Net is to use isServer = player 1, isClient = 2, but GC does not have these functions :/
What I have used is bool host = false at Start()for all players, the player who invites is the host i.e you set host = true when you invite and connection with other players were success. The host is your server and others are your clients.
Okay, and what about if you do an auto search? So there are no invites, just random people connected
Answer by OP_toss · Dec 10, 2013 at 04:56 AM
Yes you can use GameCenter, but if you plan on doing many calls in a real-time game, I'd highly recommend Unity Networking or another solution.
Assuming you're using Unity Networking...
Connecting requires a server to host a list of games. The one Unity provides is called MasterServer. You can use the built-in one, but don't deploy with it. You can download your own copy of it and run it on your own server for release.
Basically someone is the game server, the other(s) are game clients. Game server registers the game to the MasterServer, telling it the ip, port, number of players, game name, etc. Game client's can then query the MasterServer for a game of a particular type. This will return a list of servers to which they can display and pick from, or auto-find the best one.
To spawn a network-aware object, like a player, you should use Network.Instantiate. This will instantiate the object on all connected clients, and affiliate themselves with eachother using viewIDs.
I haven't used GameCenter for multiplayer games, but it seems like the wrong way to go. If the engine provides a networking solution, I'd bet it's better than sending native calls to/from iOS through GameCenter.
I use uLink, which if you can afford, I recommend. It works just like Unity's networking, but adds some better viewID tracking, much better performance, and tools and settings for optimizing and debugging.
Good luck! Hope this helps!
Okay - my main issue was trying to get the Game Center to communicate to the Unity Network Protocols, but it turns out they're are completely different, and I have to build the Game Center networking on top of my current Unity Network system.
Yep, 2 different systems entirely.
Also to deter$$anonymous$$e which player is which, if you have more than 2 players, you should ask the server. When a client joins, RPC the server asking for a new id. Server responds with a unique id, player index, w/e. A simple id could be the number of connections that have been made. Increment it every time a client connects, but don't decrement when they disconnect.
Also if this answer is correct or helped you, can you please mark it as accepted? Thanks
Your answer
Follow this Question
Related Questions
Prime31 GameCenter 2 Answers
introducing "safe" DLL causes internal compiler error 0 Answers
rpc concept 1 Answer
Multiplayer Moving Bullet 1 Answer
How to manage viewIDs? 1 Answer