Search code examples
unity-game-engineunity-networkingunity3d-unet

How to count score on all players from non player object


I've been trying to make a rocket league type game with unity 5.4 and in c#.

I've got everything with the players working and the playarea. The players are spawned by the network spawner and a ball is spawned by a ball spawner, like the enemyspawner in the tutorials. I have two goals that the ball can collide with and that resets the ball position. But how do I tell the players that there has been a goal? I've been looking everywhere and can't find a good exampel of how to pass information to the players from the ball. I have a text UI that shows on all players camera and that uses 2 variablers that count score, so what I want is to somehow increase those variables via the ball when it collides with goal.

RPC calls only work between player objects as I understand it, and syncvars does not seem to work if I try to have them between the ball and the players, anyone have any tips or can tell me what I'm missing?

EDIT: For people with the same problem. I solved this by making a scoreManager object and letting it have the scores as syncvars, then I just got the scoremanager component and its script and increased the score at the ball, then get it for the players aswell and get the score.


Solution

  • For people with the same problem. I solved this by making a scoreManager object and letting it have the scores as syncvars, then I just got the scoremanager component and its script and increased the score at the ball, then get it for the players aswell and get the score.