Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Networking;
- public class PlayerSyncPos : NetworkBehaviour
- {
- [SyncVar]
- private Vector3 syncPosition;
- public float lerpSpeed = 60;
- void FixedUpdate ()
- {
- LerpPosition ();
- TransmitPosition ();
- }
- void LerpPosition()
- {
- if (!isLocalPlayer)
- {
- transform.position = Vector3.Lerp(transform.position, syncPosition, Time.deltaTime*lerpSpeed);
- }
- }
- [Client]
- void TransmitPosition()
- {
- if (isLocalPlayer)
- {
- CmdSendPosition(transform.position);
- }
- }
- [Command]
- void CmdSendPosition(Vector3 pos)
- {
- syncPosition = pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement