Hello, in my game are max 8 people on map. I want to give number (first free from 1-8) for every player but the problem is that I don't know how to make one global object with this numbers. Actually i got (example for max 3players on map): in script in gameobject in scene: public static bool one=false; public static bool two=false; public static bool three=false; [RPC] void info(int number){ if (number== 1) scriptsname.one= true; if (number== 2) scriptsname.two= true; if (number== 3) scriptsname.three= true; } then in scripts when create players: if (scriptname.one== false) { playersnumber= 1; GameObject.Find ("objectsname").GetComponent<PhotonView> ().RPC ("info", PhotonTargets.All, playersnumber); else if (scriptname.two== false) { playersnumber= 2; GameObject.Find ("objectsname").GetComponent<PhotonView> ().RPC ("info", PhotonTargets.All, playersnumber); else if (scriptname.three== false) { playersnumber= 3; GameObject.Find ("objectsname").GetComponent<PhotonView> ().RPC ("info", PhotonTargets.All, playersnumber); } problem is that every player got number "1" and only "one" in "scriptname" is true, probably because "gameobject" is not global and everyone got different one. What should I do?
Congratulations, you are about to enter the marvellous world of static members! Google can tell you in much more detail, but in a nutshell static members are variables or functions that are not dependant on - and don't require an instance of - a class object. C# is particularly nice about them, allowing you to mix static and non-static members almost seamlessly. A quick example: Code (csharp): class Dog : MonoBehaviour { static int numDogs = 0; void Awake(){ numDogs++; Debug.Log("There are " + numDogs + "dogs!"); } } //elsehwere: Instantiate(dogPrefab); Instantiate(dogPrefab); Instantiate(dogPrefab); //output: "There are 1 dogs!" "There are 2 dogs!" "There are 3 dogs!" Good luck!
mhm this is not good solution, I have to send numbers to masterclient then check whether there are free or not