Advertisement
AndrewRosyaev

PlayerSyncPos.cs

Nov 21st, 2015
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Networking;
  4.  
  5. public class PlayerSyncPos : NetworkBehaviour
  6. {
  7.     [SyncVar]
  8.     private Vector3 syncPosition;
  9.     public float lerpSpeed = 60;
  10.  
  11.     void FixedUpdate ()
  12.     {
  13.         LerpPosition ();
  14.         TransmitPosition ();
  15.     }
  16.  
  17.     void LerpPosition()
  18.     {
  19.         if (!isLocalPlayer)
  20.         {
  21.             transform.position = Vector3.Lerp(transform.position, syncPosition, Time.deltaTime*lerpSpeed);
  22.         }
  23.     }
  24.    
  25.     [Client]
  26.     void TransmitPosition()
  27.     {
  28.         if (isLocalPlayer)
  29.         {
  30.             CmdSendPosition(transform.position);
  31.         }
  32.     }
  33.  
  34.     [Command]
  35.     void CmdSendPosition(Vector3 pos)
  36.     {
  37.         syncPosition = pos;
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement