Created
January 9, 2016 00:34
-
-
Save JosephShering/eedc95ed3ec4ccc447ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.Networking; | |
public class PlayerPositionSync : NetworkBehaviour { | |
[SyncVar] | |
private Vector3 syncPosition; | |
public Transform transform; | |
public float lerpRate = 15; | |
void FixedUpdate () { | |
TransmitPosition (); | |
LerpPosition (); | |
} | |
void LerpPosition() { | |
if(!isLocalPlayer) { | |
transform.position = Vector3.Lerp (transform.position, syncPosition, Time.deltaTime * lerpRate); | |
} | |
} | |
[Command] | |
void CmdProvidePositionToServer(Vector3 position) { | |
syncPosition = position; | |
} | |
[ClientCallback] | |
void TransmitPosition() { | |
CmdProvidePositionToServer (transform.position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment