- Home /
Photon Network RPC Random Range Problem
Hi, I'm working on a project. I'm using this script for bot money;
using UnityEngine;
using System.Collections;
public class Botmoney : MonoBehaviour {
public int BotMoney;
public bool botStealable = true;
PhotonView photonView;
// Use this for initialization
void Start () {
photonView = GetComponent<PhotonView> ();
photonView.RPC ("RandomMoneyFBot", PhotonTargets.All);
}
[RPC]
void RandomMoneyFBot(){
BotMoney = Random.Range (12,60);
}
}
But every client gets diffrent numbers. How I can solve this?
Also;
When I want RPC to a string with PhotonNetwork.playerName every player gets their own player name. I want to just write RPC sender's name to string. How can I do this?
can you elaborate more? because if you want the same number on all clients just dont random it.
@$$anonymous$$ewEight nope It's diffrent. I want to generate a random number same in the every client.
the non optimized way would be to just make it a normal function call and serialize it through the network, and trace it across clients
Answer by Suddoha · Sep 06, 2015 at 11:46 AM
That's because the remoteprocedure call will be executed on each client, so every client generates his own random number.
You have to generate it on your server and send the generated value to the clients. You can do this with a parameter if that works in the Photon framework and simply store it in BotMoney then.
Your answer
![](https://koobas.hobune.stream/wayback/20220612010810im_/https://answers.unity.com/themes/thub/images/avi.jpg)