
Untitled
By: a guest on
Aug 19th, 2012 | syntax:
C# | size: 0.95 KB | hits: 19 | expires: Never
PhotonView myPhotonView;
Transform myTransform;
bool isLocalClient;
class ExampleClass : Monobehaviour {
PhotonView myPhotonView;
Transform myTransform;
void Awake() {
myTransform = GetComponent<Transform>();
myPhotonView = PhotonView.Get(this);
isLocalClient = myPhotonView.isMine;
}
void Update() {
if(!isLocalClient) return;
myPhotonView.RPC("AskForMovement", PhotonTargets.MasterClient); //You can send things with this too, like your user's input.
}
[RPC]
void AskForMovement(PhotonMessageInfo info) {
Vector3 updatedPosition; //Example position to send to player
Quaternion updatedRotation; //Example rotation to send to player
myPhotonView.RPC("ReceiveMovement", info.sender, updatedPosition, updatedRotation); //Send this RPC back to the person that asked the master client to move
}
[RPC]
void ReceiveMovement(Vector3 pos, Quaternion rot) {
transform.position = pos;
transform.rotation = rot;
}
}