The game I am working on is using Photon PUN2 for online and when I use the editor and a build to test the multiplayer as player 1 and player 2. When I check in the editor the editor’s prefab is assigned as Player 1 and currentPlayer since it is the host but the build’s player prefab is not assigned as Player2 or otherPlayer in the Game Manager script fields of the editor. Is the normally the case because the Player1 prefab is instantiated on the editor and the player2 prefab is instantiated by the build? Or am I just messing up the implementation? My code works to switch currentPlayer and otherPlayer between Player1 and Player2 when I drag the Player2 prefab in the hierarchy to the field Player2 and otherPlayer but this is not a workable solution to play the game. I appreciate any help, the code for the GameManager script is below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using System.IO;
using TMPro;
using System.Linq;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviourPunCallbacks
{
public static GameManager instance;
//Beastiary
public GameObject Creature01;
public GameObject Creature02;
public GameObject Creature03;
public GameObject Creature04;
public GameObject Creature05;
public GameObject Creature06;
public GameObject Creature07;
public GameObject Creature08;
public GameObject Creature09;
public GameObject Creature10;
public GameObject Hercules;
public GameObject Thor;
public GameObject Horus;
public GameObject KingArthur;
public GameObject Merlin;
public GameObject Jesus;
public GameObject Mike;
public GameObject God;
public GameObject Lilith;
public GameObject Satan;
//Players
public GameObject Player1;
public GameObject Player2;
public GameObject currentPlayer;
public GameObject otherPlayer;
public GameObject tempPlayer;
public int turnnumber;
public Transform[] spawnPoints;
public void Awake()
{
CreatePlayer(); //Create a networked player object for each player that loads into the multiplayer scenes.
}
public void Start()
{
SpawnCreatures();
turnnumber = 1;
public void SpawnCreatures()
{
Debug.Log("Spawning Creatures");
if(PhotonNetwork.IsMasterClient)// If Statement that checks if player is HostMaster {MASTER = (Player 1)}
{
PhotonNetwork.Instantiate(Hercules.name, new Vector3(1, 0, 1), Quaternion.identity, 0);
PhotonNetwork.Instantiate(Thor.name, new Vector3(2, 0, 1), Quaternion.identity, 0);
PhotonNetwork.Instantiate(Horus.name, new Vector3(3, 0, 1), Quaternion.identity, 0);
PhotonNetwork.Instantiate(KingArthur.name, new Vector3(4, 0, 1), Quaternion.identity, 0);
PhotonNetwork.Instantiate(Merlin.name, new Vector3(5, 0, 1), Quaternion.identity, 0);
}
else// Else Statement that assigns for {CLIENT (Player 2)}
{
PhotonNetwork.Instantiate(Jesus.name, new Vector3(1, 0, 8), Quaternion.identity, 0);
PhotonNetwork.Instantiate(Mike.name, new Vector3(2, 0, 8), Quaternion.identity, 0);
PhotonNetwork.Instantiate(God.name, new Vector3(3, 0, 8), Quaternion.identity, 0);
PhotonNetwork.Instantiate(Lilith.name, new Vector3(4, 0, 8), Quaternion.identity, 0);
PhotonNetwork.Instantiate(Satan.name, new Vector3(7, 0, 8), Quaternion.identity, 0);
}
}
private void CreatePlayer()
{
Debug.Log(“Creating Player”);
if(PhotonNetwork.IsMasterClient)// If Statement that checks if player is HostMaster {MASTER = (Player 1)}
{
Player1 = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PhotonPlayer"), new Vector3(0, 1, 0), Quaternion.identity);
currentPlayer = Player1;
}
else// Else Statement that assigns for {CLIENT (Player 2)}
{
Player2 = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PhotonPlayer"), new Vector3(9, 1, 9), Quaternion.identity);
otherPlayer = Player2;
}
}
public void EndTurn()
{
tempPlayer = currentPlayer;
currentPlayer = otherPlayer;
otherPlayer = tempPlayer;
turnnumber += 1;
Debug.Log("Turn: " + turnnumber);
}
void Update()
{
}
}