Hi
i have been trying to add a number to the server every time a player enters
but i have been through hell i feel like the networking system doesn’t belong to unity its not friendly at all
i have spent almost a month and i still get different results than what i always expect
anyways here is the code
this code runs on start in game and if player is local
if(randomRangeTeam ==0)
{
//orange team
CmdTeamNumbers(1,0);
}
if(randomRangeTeam == 1){
//blue team
CmdTeamNumbers(0,1);
}
What is the rest of the code? How do you set randomRangeTeam? Does the Script inherit from NetworkBehaviour (assuming it is since it uses isLocalPlayer)?
Sorry i changed the code a lot can’t get it back
but i solved the issue but still i have a question
this is how i solved it
[Command]
void CmdTeamNumbersTotal(int orange, int blue,GameObject[] players)
{
//RpcTeamNumbersTotal( orange, blue,players);
foreach(GameObject player in players)
{
//player.SendMessage("Players",orange,blue);
player.GetComponent<Sync2>().Players(orange,blue);
}
}
in the host pc i looked for all the blue and orange players and now the host knows exactly the number of all players
and then to send them i stored all the players in an array and sent them the number
through Cmd
problem is i don’t feel this is the proper way
problem two SenMessage gave me an error
(“the best overloaded method match for unityengine.gameobject.SendMessage(string,object,unityengine.sendmessage
option”) has some invalid arguments
SendMessage only takes one object paramenter, you could encapsulate the data in an array like:
player.SendMessage("Players", new int[]{ orange, blue });
What’s wrong with the RPC call? You should probably just have one static Class that keeps track of all that global network data and syncs it that all the players can access.
I don’t know what you mean by static and RPC call
does the static matter when we use the networking system?
i mean there is no pc that can reach any pc unless we send the information to it
but when we use static we don’t send the information we take it because there is only one variable with
statics but how can we take it if its not in our pc? meaning there is not only one variable even if its static
i might be wrong i don’t know how statics work with the network system but i hope you may correct me
and for the RPC call i didn’t use any RPC’s
are you suggesting that i use it with static?
sorry i don’t have networking background but hope you can help me little bit more