Hello everyone,
I would like to share my problem with PUN and looking for an explanation or solution if possible. I have used official PUN tutorial and extended it with my own prefabs with success. I can join rooms with multiple clients and instantiate my ship prefab.
Basic concept is that there is a gameobject called "CameraPivot" with "MainCamera" as its child object. Whenever, a player joins, the CameraPivot object has to be attached to the instantiated player ship locally. If there is only the host, it works OK. When a client joins, the camera works for the client side as well. However, the CameraPivot object with MainCamera gets reset to intial position for the host and camera gets locked. I connected up to 5 clients to the host, and all the clients work flawless but the host.
[img][/img]
![J6qtfOC.png]()
I have found that others have similar issues as in below link as well,
https://forum.unity.com/threads/photon-cameras-not-working-when-more-than-one-exist.691867/
Also, when I created and joined the scene with 6 players, the problem occured to be related only to the host player. I disconnected the host, the second player becomes the host. And right after the second player becomes host, it loses the camarapivot with maincamera. When I disconnected the second player which is the host now, the same happens with the 3rd player.
I tried assigning the camerapivot both from gamemanager and the player prefab. Below is the GameManager script that instantiates the players/cameras and the Camera script. So anyone has any idea why this happens or how to overcome this issue? (I am quite new to both Unity and Photon, so I might have overlooked something easy)
void Start()
{
Instance = this;
if (playerPrefab == null)
{
Debug.LogError("<Color=Red><a>Missing</a></Color> playerPrefab Reference. Please set it up in GameObject 'Game Manager'", this);
}
else if (ShipManager.LocalPlayerInstance == null)
{
Debug.LogFormat("We are Instantiating LocalPlayer from {0}", SceneManagerHelper.ActiveSceneName);
// we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
GameObject LocalShip = PhotonNetwork.Instantiate(this.playerPrefab.name, new Vector3(UnityEngine.Random.Range(0, 200), 3, 0f), Quaternion.identity, 0);
if (!LocalShip.GetPhotonView().IsMine)
{
Camera.main.GetComponent<CameraOrbit>().enabled = false;
}
else
{
Camera.main.GetComponent<CameraOrbit>().enabled = true;
CamPivot = GameObject.Find("CameraPivot");
CamPivot.GetComponent<CameraSystem>().shipView = LocalShip.GetComponent<CameraAssign>().sView;
CamPivot.GetComponent<CameraSystem>().portsideView = LocalShip.GetComponent<CameraAssign>().prtView;
CamPivot.GetComponent<CameraSystem>().starboardView = LocalShip.GetComponent<CameraAssign>().stbView;
Camera.main.GetComponent<CameraOrbit>().victory = LocalShip;
}
}
else
{
Debug.LogFormat("Ignoring scene load for {0}", SceneManagerHelper.ActiveSceneName);
}
}