Hi. I have been playing around with Networking and was wondering if it is possible to have variables set up on the Server for all clients to access?
For instance each player spawned prefab would inherent an int tag value. Once one is assigned to a player prefab it increments the value, then the next generated player prefab gets the next value.
My current set up, in the player prefab script asks a master game script to return a number.
void GetTagNumber(){
GameObject gameScript = GameObject.Find ("GameScript");
GameScript script = (GameScript)gameScript.GetComponent(typeof (GameScript));
playerTagValue = script.GivePlayerTagNumber();
testText.text = "Value: " + playerTagValue; // shows value on Text on screen
}
In my master game script, I then return and increment the value.
private int playerTag = 0;
public int GivePlayerTagNumber(){
playerTag++;
return playerTag;
}
When I tested it out all the players were given the same value. It then dawned on me that each spawn player has it’s own GameScript, which I use to run the game. since they are all different scripts it updates the value on their copy of the GameScript. I need a universal script if that is possible.
Thanks.