from github
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
//this script syncs player components position and rotation in a local space
|
||||
|
||||
public class PlayerComponentNetworkSync : NetworkBehaviour
|
||||
{
|
||||
private NetworkVariable<Vector3> pos = new NetworkVariable<Vector3>(writePerm: NetworkVariableWritePermission.Owner);
|
||||
private NetworkVariable<Quaternion> rot = new NetworkVariable<Quaternion>(writePerm:NetworkVariableWritePermission.Owner);
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//the owner of the player object should write to the network variable, all others should read it
|
||||
if (IsOwner)
|
||||
{
|
||||
pos.Value = transform.localPosition;
|
||||
rot.Value = transform.localRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = pos.Value;
|
||||
transform.localRotation = rot.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user