using Unity.Netcode; using UnityEngine; namespace HelloWorld { public class HelloWorldPlayer : NetworkBehaviour { public NetworkVariable Position = new NetworkVariable(); public override void OnNetworkSpawn() { if (IsOwner) { Move(); } } public void Move() { if (NetworkManager.Singleton.IsServer) { var randomPosition = GetRandomPositionOnPlane(); transform.position = randomPosition; Position.Value = randomPosition; } else { SubmitPositionRequestServerRpc(); } } [ServerRpc] void SubmitPositionRequestServerRpc(ServerRpcParams rpcParams = default) { Position.Value = GetRandomPositionOnPlane(); } static Vector3 GetRandomPositionOnPlane() { return new Vector3(Random.Range(-3f, 3f), 1f, Random.Range(-3f, 3f)); } void Update() { transform.position = Position.Value; } } }