- Home /
I'm trying to generate a random key and share it with other players when they join the game i'm using PUN. it's not working please help!
This is the code that i'm currently using, i've tried may different logic but it's no use. can someone please point out the problem? i think i'm using the RPC wrong.
public class GeneratingKey : Photon.MonoBehaviour {
int random;
string key = null;
string RandomKey = "";
void Start() {
if(PhotonNetwork.countOfPlayers == 1 && key == null)
{
for (int i = 0; i < 30; i++) {
random = Random.Range (1, 5);
RandomKey = RandomKey + random.ToString();
}
key = RandomKey;
}
if (key != null) {
ProceduralNumberGenerator.SetKey (key);
}
}
void Update(){
photonView.RPC ("SetKey", PhotonTargets.Others, key);
if (key != null)
Debug.Log (key);
ProceduralNumberGenerator.SetKey (key);
}
// Update is called once per frame
[PunRPC]
void SetKey (string tempString) {
if (key == null) {
key = tempString;
}
}
}
Comment
For anyone who is interested, we have the same discussion here.
Your answer
Follow this Question
Related Questions
Photon Unity Networking carrying scene objects 1 Answer
Photon PUN 2 RPC function doesn't change a variable value 2 Answers
Photon PUN rpc function doesnt update the variable to a new joined player 0 Answers
Photon PUN2, Rpc score can't correctly. 1 Answer
Sending int value owned by Masterclient to other client 2 Answers