Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

I'm trying to generate a random key and share it with other players using RPC.

$
0
0
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;
}
}
}

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>