from github

This commit is contained in:
jonas
2024-10-29 17:16:17 +01:00
commit 537f1d77fb
1074 changed files with 303521 additions and 0 deletions
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Unity.Netcode;
using UnityEngine;
//this script syncs player components position and rotation in a global space
public class PlayerGlobalCompontentSync : NetworkBehaviour
{
//the owner of the player object should write to the network variable, all others should read it
private NetworkVariable<Vector3> pos = new NetworkVariable<Vector3>(writePerm: NetworkVariableWritePermission.Owner);
private NetworkVariable<Quaternion> rot = new NetworkVariable<Quaternion>(writePerm: NetworkVariableWritePermission.Owner);
private void Update()
{
if (IsOwner)
{
pos.Value = transform.position;
rot.Value = transform.rotation;
}
else
{
transform.position = pos.Value;
transform.rotation = rot.Value;
}
}
}