- Home /
View PvP scores on screen in real-time
Could someone point me in the right direction as to how I'd be able to implement a PvP multiplayer feature into my game?
Here's a little background on how the game is set up:
Its a 2D game where you simply tap on gameObjects to gain points, and after one has been tapped, it destroys itself and spawns a new clone in another location of the screen.
It's a multi-platform game for Android and iOS.
The main camera in all scenes doesn't move at all, and the player controller is merely an empty gameObject with an attached script.
I want the players to be able to see the other person's score in real-time, but I don't want them to be playing on the same field because since it's a tap based game, it would throw the two players off to see gameObjects disappearing from their view and reappearing randomly. I've attached a concept image below.
I'm using the Badumna Networking System and will incorporate a working log-in system, however I am willing to change the way I set up my networking because I haven't started the multiplayer/networking feature yet. I'm just asking for a solid way to make the feature work the way I stated above in bold.
I've only researched the Networking capabilities of Unity. I have experience in UnityScript and C# but I have no idea how to script the networking components which is my reason for using Badumna. This is my first major Unity project and I've done a lot with it. Multiplayer is the last part of my game that needs to be done before I release a beta version.
Any help on getting this to work will be greatly appreciated. I will even put your names in the credits when the game is finished and released. I'll also be starting a thread up in a few days in the community forums for my game if anyone is interested to see what I've been working on.
Answer by Corentin · Jan 26, 2014 at 03:00 PM
I don't know anything with Badumna, but I'd implement this with a single NetworkView, setup like this : observe => None and State Synchronization => Off. This NetworkView Component has to be in a scene object (not created at runtime), so that it will be "shared" (same NetworkView ID) by every client on the server. It won't synchronize anything, since you only want to send scores to the other player. You should use an RPC for this, and use networkView.RPC("SetScore",RPCMode.Others, myScore); define the "SetScore" function like this :
[RPC]
void SetScore(int score){
otherPlayerScore = score;
}
You've pretty much answered my question. I don't even need the Badumna stuff anymore. I've set up the GameObject in the scene, and I know to put that piece of code into my script, but where do I call the networkView.RPC("SetScore",RPC$$anonymous$$ode.Others, myScore); at?
You can call the RPC whenever the score changes (the script will need a reference to the networkView Component). You could define a property for your score and call the rpc in the set function : public int Score(int value){ get {return myScore}; set { myScore = value; networkView.RPC("SetScore",RPC$$anonymous$$ode.Others, myScore);}}
$$anonymous$$aybe a AddToScore(int scoreIncrease) function would be better, that's up to you.
I placed the call in the update of another controller in the scene and it works, however I don't think it's the most efficient way to send the data because it resends it every single frame. But for now, it will do. Thanks again!
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
On screen scoring in multiplayer 1 Answer
Can you create a Stand alone server for your game? 0 Answers
Networking, players can't see each others movements 1 Answer