Sorry if this is a duplicate question.
I found this Reddit post which is exactly my current problem. https://www.reddit.com/r/Unity2D/comments/lw96s5/multiplayer_cameras/
However, there's only one comment which isn't that descriptive and doesn't have any links to the 'tutorial'. To rephrase, I have a MLAPI game in Unity with a LocalPlayer
prefab(has a camera, FPS movement code, and PlayerInput) and a ServerPlayer
(does not have a camera or PlayerInput component) prefab. They represent different replicated players in my game.
The current problem is the code to decide whether to spawn a local player or a remote player.
Deciding what prefab to spawn:
private void ApprovalCheck(byte[] connectionData, ulong clientId, MLAPI.NetworkManager.ConnectionApprovedDelegate callback)
{
//Your logic here
bool approve = connectionData == System.Text.Encoding.ASCII.GetBytes("xd");
bool createPlayerObject = true;
if (NetworkManager.Singleton.ConnectedClients[clientId].PlayerObject.IsLocalPlayer)
{
localPlayerPrefab.GetComponent<NetworkObject>()
.SpawnAsPlayerObject(clientId);
}
else
{
serverPlayerPrefab.GetComponent<NetworkObject>()
.SpawnAsPlayerObject(clientId);
}
//If approve is true, the connection gets added. If it's false. The client gets
disconnected
callback(createPlayerObject, null, approve, positionToSpawnAt, Quaternion.identity);
}
Let me know if you need any extra details.