mirror of
https://github.com/zoriya/Skillfight.git
synced 2026-05-17 13:06:57 +00:00
31 lines
615 B
C#
31 lines
615 B
C#
using UnityEngine.Networking;
|
|
using UnityEngine;
|
|
|
|
public class SyncPosition : NetworkBehaviour
|
|
{
|
|
[SyncVar]
|
|
public Vector3 playerPosition;
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
SetPosition ();
|
|
if (!isLocalPlayer)
|
|
{
|
|
transform.position = Vector3.Lerp(transform.position, playerPosition, Time.deltaTime * 15);
|
|
}
|
|
}
|
|
|
|
[Command]
|
|
void CmdServerPosition (Vector3 position)
|
|
{
|
|
playerPosition = position;
|
|
}
|
|
|
|
[ClientCallback]
|
|
void SetPosition ()
|
|
{
|
|
if (isLocalPlayer)
|
|
CmdServerPosition(transform.position);
|
|
}
|
|
}
|