这是我的网络管理员脚本。它应该连接到一个随机的大厅,当它没有找到任何大厅时,它会创建一个新大厅。在它之后,它会选择一个随机的生成点并为每个玩家激活相机和脚本。
我想问为什么它会产生两个玩家并且你控制它们但只看到一个相机?
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
SpawnSpot[] spawnSpots;
// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
Connect ();
}
void Connect () {
PhotonNetwork.ConnectUsingSettings ("GCE_Mk2");
}
void OnGUI () {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}
void OnConnectedToMaster () {
Debug.Log ("Connected");
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed () {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
SpawnMyPlayer ();
}
void SpawnMyPlayer () {
if (spawnSpots == null) {
Debug.LogError ("No Spawns");
return;
}
SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("RigidBodyFPSController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
((MonoBehaviour)myPlayerGO.GetComponent ("RigidbodyFirstPersonController")).enabled = true;
myPlayerGO.transform.FindChild ("MainCamera").gameObject.SetActive (true);
}
}