Photon Specific Variables
gloomiie
✭
Hello, I'm trying to get a variable that is player specific that, when that specific player does something, it modifies only that player's variable. I believe the best way is a RPC and I'm unsure whats not working here. The code is working as intended until I try to modify it based on a specific player. I would like to note that I'm not trying to get a specific group of people, but rather 1 specific person.
void rest(){
if (sleeping == true && sleepbar <= 100) {
transform.GetComponent<PhotonView> ().RPC ("resting", PhotonNetwork.player, decrease);
}
if(sleeping == false) {
transform.GetComponent ().RPC ("notsleeping", PhotonNetwork.player, decrease);
}
}
[PunRPC]
public void notsleeping( int amt){
sleepbar -= amt;
}
[PunRPC]
public void resting( int amt){
sleepbar += amt;
}
void rest(){
if (sleeping == true && sleepbar <= 100) {
transform.GetComponent<PhotonView> ().RPC ("resting", PhotonNetwork.player, decrease);
}
if(sleeping == false) {
transform.GetComponent ().RPC ("notsleeping", PhotonNetwork.player, decrease);
}
}
[PunRPC]
public void notsleeping( int amt){
sleepbar -= amt;
}
[PunRPC]
public void resting( int amt){
sleepbar += amt;
}
0
Comments
-
It usually is best to use Custom Player Properties for anything player-related that does not change very frequently. An RPC is better to affect some object and it's not good, if you ever have players joining late.
If the values change a lot, send them with OnPhotonSerializeView.
This might help:
https://doc.photonengine.com/en-us/pun/current/tutorials/rpcsandraiseevent
See also:
https://doc.photonengine.com/en/pun/current/tutorials/synchronization-and-state
In doubt, post in the PUN sub-forum and explain what happens and what you'd expect to happen. Without more details, we can hardly help.0 -
Thank you so much, I will definitely post there if I need more help. Thank you again0