Photon Network Client Reading empty variables when connect
This part of script is running when player connects, it finds 3 GameObjects in scene (spawnPlacers), for master-moves his unit to 1st place, for client it checks if this spawnPoints is empty:
[RequireComponent( typeof( PhotonView ) )] public class GameStart : Photon.MonoBehaviour { public GameObject[] l_spawnPlace;
public virtual void Start()
{
PhotonNetwork.autoJoinLobby = false; // we join randomly. always. no need to join a lobby to get the list of rooms.
l_spawnPlace = new GameObject[]{ null, null, null };
l_spawnPlace[0] = GameObject.Find("SpawnPlace1");
l_spawnPlace[1] = GameObject.Find("SpawnPlace2");
l_spawnPlace[2] = GameObject.Find("SpawnPlace3");
Array.Resize (ref UnitGroup, _UnitGroupSize);
}
public void OnJoinedRoom()
{
GameObject l_SpawnGameObject = null;
if (!PhotonNetwork.isMasterClient) {
foreach (GameObject i in l_spawnPlace) {
if (i.GetComponent<SpawnPoint> ().SpawnPointHero == null) {
l_SpawnGameObject = i;
}
}
Vector3 spawnPlasePos = l_SpawnGameObject.transform.position;
GameObject PlayerHero = PhotonNetwork.Instantiate ("Cha_Knight", spawnPlasePos, Quaternion.identity, 0);
PlayerHero.name = "PlayerHero" + PhotonNetwork.player.ID;
l_SpawnGameObject.GetComponent<SpawnPoint> ().DoHeroBinding (PlayerId);
} else {//if master
l_SpawnGameObject = l_spawnPlace[0];
Vector3 spawnPlasePos = l_SpawnGameObject.transform.position;
GameObject PlayerHero = PhotonNetwork.Instantiate ("Cha_Knight", spawnPlasePos, Quaternion.identity, 0);
PlayerHero.name = "PlayerHero1";
l_SpawnGameObject.GetComponent<SpawnPoint> ().DoHeroBinding (1);
}
}
This is SpawnPointScript on SpawnPlace GameObjects:
public class SpawnPoint : Photon.MonoBehaviour {
public GameObject SpawnPointHero = null;
public PhotonView SpawnPointView = null;
public void DoHeroBinding(int PlayerId){
photonView.RPC ("Bind", PhotonTargets.AllBuffered, PlayerId);
}
[RPC]
public void Bind(int PlayerId, PhotonMessageInfo info){
SpawnPointHero = GameObject.Find("PlayerHero"+PhotonNetwork.player.ID);
SpawnPointView = SpawnPointHero.GetComponent<PhotonView> ();
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if (stream.isWriting == true)
{
stream.SendNext (SpawnPointView);
Debug.Log ("isWriting SpawnPointScript");
}
else
{
SpawnPointView = (PhotonView)stream.ReceiveNext ();
Debug.Log ("isReading SpawnPointScript");
}
}
}
So, when Client connects, it reads that SpawnPoint[0] is empty, but at master side SpawnPoint[0] is binded by master's unit =(.
[2]: http://images.vfl.ru/ii/1476850351/0a24b164/14578280.jpg
Your answer
Follow this Question
Related Questions
Noob problem with Photon 0 Answers
Photon & Unity Question 0 Answers
How both players can control the soccer ball in 2 player football game 1 Answer
Photon Join Random CustomRoomProperties not working 0 Answers