I was making an online FPS game so when I was updating my look script I decided to use a ServerRpc for looking when trying with parallel sync the client could not look around here is my code:
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class NetworkLookAround : NetworkBehaviour
{
[SerializeField] private float sensX;
[SerializeField] private float sensY;
[SerializeField] private Transform orientation;
private float xRotation;
private float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
if (!IsLocalPlayer) return;
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX ;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY ;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
if (IsServer)
{
this.transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
this.orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
else
{
Debug.Log("Using ServerRpc");
TurnPlayerServerRpc(xRotation, yRotation);
}
}
[ServerRpc]
private void TurnPlayerServerRpc(float xRot, float yRot)
{
// Rotate The Camera
transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
Debug.Log("ServerRpc Rotating player");
}
}
The rpc is running as expected on the server but no rotation is being applied if you know whats going on please help