Void is executed as many times as clients are connected (It doesn't relate to Photonview.ismine)

When there are 2 players online: Player A and Player B.

Then, Player A hits a Box and decrease it's life in 20, but as there are 2 clients it gets called twice, so BoxLife gets decreased by 40. public int BoxLife=100;

I handle that decrease by this way: 1. The box does NOT have photonview. 2. It has a script called BoxScript.cs. 3. There's a BoxManager with Photonview to execute the RPC required to damage or destroy the box.

When the box collide with the bullet: BoxScript.cs gets the bullet damage and sends it to BoxManager(BoxesManager.cs)

In BoxScript.cs :
void SendDatatoBM(string Name, int DmgToSend) { GameObject BoxesMan = GameObject.FindGameObjectWithTag("BoxesManager"); BoxesManagerScript = BoxesMan.GetComponent<BoxesManager>(); BoxesManagerScript.SendDamageThatBox(gameObject.name,DmgToSend); }

In BoxesManager.cs : It receives the data
public void SendDamageThatBox(string BoxNameToDecreaseLife, int Damage) { PhotonView pv = PhotonView.Get(this); pv.RPC("DmgThatBoxOverNetwork", PhotonTargets.AllBufferedViaServer,BoxNameToDecreaseLife,Damage); }

[PunRPC] public void DmgThatBoxOverNetwork(string BoxName, int Damage) { GameObject BoxToSendDamage = GameObject.Find(BoxName); ScriptToHandleBoxLife = BoxToSendDamage.GetComponent<BoxScript>(); ScriptToHandleBoxLife.ReceiveDamage(Damage); }

Now the BoxManager decreases the box life by accessing to ReceiveDamage(int DmgToReceive), void in BoxScript.cs:

public void ReceiveDamage(int DmgToReceive) { BoxLife -= DmgToReceive; }

So I'd like to know how to call SendDatatoBM(string Name, int DmgToSend) only once without taking account there are many clients trying to call this once in each... I wouldn't like to do this via MasterClient because if it has lag, then every single client would be desynced and it'd mess up everything..

Thanks by the way, hope someone can help me :smile:
Sign In or Register to comment.