Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: C#  |  size: 0.95 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PhotonView myPhotonView;
  2. Transform myTransform;
  3. bool isLocalClient;
  4.  
  5. class ExampleClass : Monobehaviour {
  6.         PhotonView myPhotonView;
  7.         Transform myTransform;
  8.  
  9.         void Awake() {
  10.                 myTransform = GetComponent<Transform>();
  11.                 myPhotonView = PhotonView.Get(this);
  12.                 isLocalClient = myPhotonView.isMine;
  13.         }
  14.  
  15.         void Update() {
  16.                 if(!isLocalClient) return;
  17.                 myPhotonView.RPC("AskForMovement", PhotonTargets.MasterClient); //You can send things with this too, like your user's input.
  18.         }
  19.  
  20.         [RPC]
  21.         void AskForMovement(PhotonMessageInfo info) {
  22.                 Vector3 updatedPosition; //Example position to send to player
  23.                 Quaternion updatedRotation; //Example rotation to send to player
  24.                 myPhotonView.RPC("ReceiveMovement", info.sender, updatedPosition, updatedRotation); //Send this RPC back to the person that asked the master client to move
  25.         }
  26.  
  27.         [RPC]
  28.         void ReceiveMovement(Vector3 pos, Quaternion rot) {
  29.                 transform.position = pos;
  30.                 transform.rotation = rot;
  31.         }
  32. }