I have a camera attached to the player prefab that is instantiated by the NetworkManager.
After the host starts the game everything behaves correctly, but once the client joins the game, the host switches cameras and now both the client and the host are controlling the client camera.
I'm not sure why this is happening and couldn't debug the issue.
For your reference, this is the player look script that I have on the camera:
using Unity.Netcode;
public class PlayerLook : NetworkBehaviour
{
public float sensitivity = 100f; // Mouse sensitivity
private Transform player; // Reference to player transform
private float xRotation = 0f; // Current rotation around the x-axis
void Start()
{
player = this.transform.parent; // Set player reference
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
player.Rotate(Vector3.up * mouseX);
}
}
Can't say I have worked with Multiplayer before, but I'm not sure it's correct to have both players have their own cameras. Regardless, if they must have it, for example when you want to show split screen or sth, then you better have either one or both cameras of the players render into a RenderTexture(s) and one camera to render whatever composition you want. Because as it is, you probably have two cameras rendering in the same Display. The code posted above does not, in and of itself, affect anything imho. You probably only see the last camera rendered in your Scene view. If not, then perhaps look for references to Camera.main elsewhere and check both cameras for the MainCamera tag. Only one camera should have that tag within the same scene. I'd also look into Cinemachine. You can have vcams instead of Unity's Camera as children and only one Unity Camera in the scene. vcams are proxies driving the Unity camera, so you can switch between them or even blend etc.