- Home /
Multiplayer cant see host player C#
Hello again, i am having some trouble getting some aspects of multiplayer to work. im using Photon and this is my Network Manager script:
 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     private const string typeName = "ShadyFoxStudiosTestGame";
     private const string gameName = "SFS_Test";
     private HostData[] hostList;
     public GameObject playerPrefab;
     public GameObject spawnPointObj;
     public Transform spawnPoint;
     public GameObject standbyCamera;
     bool shouldSpawn = false;
 
     void Awake(){
         DontDestroyOnLoad(gameObject);
     }
 
     void Start(){
     }
 
     void Update(){
         if(shouldSpawn){
             StartCoroutine(SpawnCount(3));
             shouldSpawn = false;
         }
     }
     
     private void StartServer()
     {
         Application.LoadLevel ("TestRoom");
         Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
         MasterServer.RegisterHost(typeName, gameName);
     }
     void OnServerInitialized()
     {
         //Debug.Log("Server Initializied");
         shouldSpawn = true;
         //standbyCamera.gameObject.SetActive (false);
     }
     void OnGUI()
     {
         if (!Network.isClient && !Network.isServer)
         {
             if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                 StartServer();
             
             if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
                 RefreshHostList();
             
             if (hostList != null)
             {
                 for (int i = 0; i < hostList.Length; i++)
                 {
                     if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
                         JoinServer(hostList[i]);
                 }
             }
         }
     }
     private void RefreshHostList()
     {
         MasterServer.RequestHostList(typeName);
     }
     
     void OnMasterServerEvent(MasterServerEvent msEvent)
     {
         if (msEvent == MasterServerEvent.HostListReceived)
             hostList = MasterServer.PollHostList();
     }
     private void JoinServer(HostData hostData)
     {
         Network.Connect(hostData);
     }
     
     void OnConnectedToServer()
     {
         Application.LoadLevelAdditive ("TestRoom");
         Debug.Log("Server Joined");
         shouldSpawn = true;
         //standbyCamera.gameObject.SetActive (false);
     }
     private void SpawnPlayer()
     {
         spawnPointObj = GameObject.Find("SpawnPoint");
         spawnPoint = spawnPointObj.transform;
         GameObject myPlayer = (GameObject) Network.Instantiate(playerPrefab, spawnPoint.transform.position, Quaternion.identity, 0);
         myPlayer.GetComponent<CharacterControler>().enabled = true;
         myPlayer.transform.FindChild("Player1_Camera").gameObject.SetActive (true);
         standbyCamera = GameObject.Find("StandbyCamera");
         standbyCamera.gameObject.SetActive (false);
     }
     public IEnumerator SpawnCount(float delay){
         yield return new WaitForSeconds(delay);
         SpawnPlayer();
     }
 }
this is ran from the main menu. when the client connects to the server the host can see them but they cant see the host if i just use loadlevel, but if i use loadleveladditive the camera only shows grey. also despite having a "network view" on every moving object nothing except the players update on the server (aka if you pick up a gun it only disappears on the person who picked it ups screen.
sorry if this didnt make much sense but its hard to explain. thanks for any help.
Can't give a proper answer because I can't analyze your code now.
However, this seems to be related to loading levels and I recently posted a reply with tips to a forum thread. Head over to:
http://forum.unity3d.com/threads/instantiate-problem-for-new-players.259631/#post-1716680
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                