- Home /
How do I create an online object counter
I'm sorry for my English if something is wrong, well what happens is that I have decided to create an online horror game, what happens is that I want when a player takes a soul to show it to the other player, apparently the accountant bugea and the other player gets 0/7 and another 5/7 The code is in Spanish Here the script (JS):
var Almas : int;
var AlmasLimit = 7;
var SceneWinGame : String;
var chatScript : FPSChat;
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "Alma"){
networkView.RPC("AlmaRecogida", RPCMode.All, Almas);
Destroy(other.gameObject);
}
}
function OnGUI(){
if(networkView.isMine){
GUILayout.Label("ALMAS: " + Almas + " / " + AlmasLimit);
}
}
function Update(){
if(Almas == 7){
networkView.RPC("WinGame", RPCMode.All, SceneWinGame);
}
}
@RPC
function AlmaRecogida(alma : int){
Almas = alma;
alma += 1;
}
@RPC
function WinGame(LoadScene : String){
SceneWinGame = LoadScene;
Application.LoadLevel("Win_Scene");
}
Is there a reason you're using old Networking classes as opposed to Unet?
if what happens is that I get used to the old system and also that the UNET I'm not used to it and I don't adapt 100%
Answer by mehtanitish · Sep 06, 2019 at 05:05 AM
Hi,
I have implemented an online score counter in my game where I used Photon's PUN. I have few questions before I can help you. - What type is this networkView and what object does it reference to? - What engine are you using for multiplayer, like PUN, UNET or anything else? - And the script you have pasted above is on your multiplayer object? - Are you able to see counter doing fine on one client but not on another? - Is this counter value binded to your Online player object? so in that case each client shows two player objects and hence two counters, correct me if I am wrong.
Thanks
The engine I use is the old raknet system, and the script above has been pasted on the player and on one client it works and the other does not, I have already tried everything that came to $$anonymous$$d and I no longer have left more ideas if you could help me it would be the best
What type is this networkView and what object does it reference to?
You mentioned on one client it works, say two players A and B are connected on two clients, Client 1 is player A and Client 2 is player B. Player A took 5 souls so its counter on Player A is 5 for Client 1 but for Client 2 Player A shows 0. Is this right? Or You see count 5 on both clients for Player A but 0 on player B?
I do not understand you very well with the networkView, and above all it is exactly what happens to me, one player takes a soul and the other does not get that he has picked it up
Your answer
Follow this Question
Related Questions
How to implement online multiplayer in a simple 1v1 game? 2 Answers
Unity networking tutorial? 6 Answers
Should I be using peer-to-peer networking for my 1v1 game? 1 Answer
Unity Multiplayer 1 Answer