This commit is contained in:
Dominik G.
2025-10-12 12:01:26 +02:00
parent 515160b1ec
commit 0f716ab4a7
3 changed files with 54 additions and 36 deletions

View File

@@ -268,6 +268,46 @@ namespace MegaKoop.Game.Networking
}
}
// Ensure only the local player's camera remains active and is MainCamera
if (info.IsLocal)
{
foreach (var cam in cameras)
{
cam.tag = "MainCamera";
cam.enabled = true;
cam.gameObject.SetActive(true);
}
// Disable any other active cameras that are not part of this player
foreach (var otherCam in UnityEngine.Object.FindObjectsOfType<Camera>())
{
if (!otherCam.transform.IsChildOf(clone.transform))
{
otherCam.enabled = false;
}
}
// Ensure there is exactly one enabled AudioListener (on this player)
foreach (var otherListener in UnityEngine.Object.FindObjectsOfType<AudioListener>())
{
if (!otherListener.transform.IsChildOf(clone.transform))
{
otherListener.enabled = false;
}
}
// Bind the character controller to this camera for input-relative movement
var controller = clone.GetComponent<ThirdPersonCharacterController>();
if (controller != null)
{
Transform camTransform = thirdPersonCamera != null ? thirdPersonCamera.transform : (Camera.main != null ? Camera.main.transform : null);
if (camTransform != null)
{
controller.SetCameraTransform(camTransform);
}
}
}
}
private static string BuildPlayerName(LobbyPlayerInfo info, int index)

View File

@@ -76,6 +76,11 @@ namespace MegaKoop.Game
inputSource = source;
}
public void SetCameraTransform(Transform cam)
{
cameraTransform = cam;
}
private Vector2 ReadMovementInput()
{
if (inputSource != null)