Hello, im working on a multiplayer top down shooter with PUN as the networking library but i have a problem.
The lobby system work perfectly, when i press the “start game” button. Then the GameScene loads correctly, the PlayerManager Object is created like it should but it only create one PlayerController object for the current Player.
Example: I join the room “TestRoom” from Unity with the nickname “UnityClient”, and from the WebGL build with the nickname “WebClient”. When i click StartGame (from the UnityClient since its the room creator) the scene switch correctly, the PlayerManager Objects gets created too, but not my PlayerController, it gets created only locally.
Code:
Start button function:
public void StartGame()
{
PhotonNetwork.CurrentRoom.IsOpen = true;
PhotonNetwork.CurrentRoom.IsVisible = false;
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.LoadLevel(1); //1 is the scene index
}
}
When the scene change:
void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if (scene.buildIndex != 0) // Not in menu scene --> We're in the game scene
{
var pm = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerManager"), Vector3.zero, Quaternion.identity);
print("Instantiated " + pm);
}
}
When the PlayerManager is created:
void Start()
{
PV = GetComponent<PhotonView>();
print(PV);
if (PV.IsMine)
{
//Create the player controller
var pc = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerController"), Vector3.zero, Quaternion.identity);
print("Created the player " + pc.name + " for: " + pc.GetComponent<PhotonView>().Owner);
//StartCoroutine("spawnCo");
}
}
Heres some screenshot if it can helps:
Lobby:
When joining:
I dont get what i missed.
Sorry for the grammar not a native speaker.