1
這裏是解決的代碼。PhotonNetworking Unity播放器產卵不通過網絡工作
解決[]
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
/*
public Camera standbyCamera;*/
// Use this for initialization
SpawnSpot[] spawnSpots;
void Start() {
Connect();
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGui(){
Debug.Log ("OnGui" + PhotonNetwork.connectionStateDetailed.ToString());
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
// Update is called once per frame
void OnJoinedLobby() {
Debug.Log ("Joined Lobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("Joined Room");
SpawnMyPlayer();
}
private GameObject pivot;
private GameObject topDownCam;
public void SpawnMyPlayer(){
SpawnSpot mySpawnSpot = spawnSpots [ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayer = PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
//standbyCamera.enabled = false;
myPlayer.gameObject.SetActive (true);
topDownCam = GameObject.FindWithTag("TopDown");
topDownCam.GetComponent<Camera>().enabled = true;
try
{
pivot = GameObject.FindWithTag("PivotObject");
pivot.GetComponent<MouseLook>().enabled = true;
MouseLook mouseScript = myPlayer.GetComponentInChildren<MouseLook>();
if(mouseScript != null)
{
mouseScript.enabled = true;
}
CharMove moveScript = myPlayer.GetComponentInChildren<CharMove>();
if(moveScript != null)
{
moveScript.enabled = true;
}
CharacterController controlScript = myPlayer.GetComponentInChildren<CharacterController>();
if(controlScript != null)
{
controlScript.enabled = true;
}
Camera childCam = myPlayer.GetComponentInChildren<Camera>();
if(childCam != null)
{
childCam.enabled = true;
}
}
catch
{
Debug.Log ("Error finding children");
}
}
}
所以我有一個統一的項目IM工作的,我們使用光子網絡我重視玩家的結構的圖像和與之相關的腳本。由於某種原因,當我加載兩名球員時,他們無法看到對方。
我知道如果我不禁用播放器,我會看到兩者,但控件將全部搞砸了,但是如果我禁用與角色的每個元素相關的腳本,並且讓角色像教程一樣啓用說我無法選擇腳本出於某種原因,我不知道如何去組件。
我得到一個失敗的加入這裏的控制檯輸出
Failed Join
UnityEngine.Debug:Log(Object)
NetworkManager:OnPhotonRandomJoinFailed() (at Assets/Game Assets/Prefab/Resources/Scripts/NetworkManager.cs:28)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1865)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1223)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83)
但隨後的連接和不失敗
Joined Room
UnityEngine.Debug:Log(Object)
NetworkManager:OnJoinedRoom() (at Assets/Game Assets/Prefab/Resources/Scripts/NetworkManager.cs:32)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1865)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1708)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83)
這裏是我的NetworkManager的
/*
public Camera standbyCamera;*/
// Use this for initialization
SpawnSpot[] spawnSpots;
void Start() {
Connect();
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGui(){
Debug.Log ("OnGui" + PhotonNetwork.connectionStateDetailed.ToString());
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
// Update is called once per frame
void OnJoinedLobby() {
Debug.Log ("Joined Lobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("Joined Room");
SpawnMyPlayer();
}
void SpawnMyPlayer(){
SpawnSpot mySpawnSpot = spawnSpots [ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayer = PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
//standbyCamera.enabled = false;
myPlayer.gameObject.SetActive (true);
//((MonoBehaviour)myPlayer.GetComponent("CharacterController")).enabled = true;
//((MonoBehaviour)myPlayer.GetComponent("CharMove")).enabled = true;
}
}
新開發 如果我參加的團結,然後與另一名球員,我得到以下錯誤
Received OnSerialization for view ID 2001. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined
UnityEngine.Debug:LogWarning(Object)
NetworkingPeer:OnSerializeRead(Hashtable, PhotonPlayer, Int32, Int16) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3342)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1758)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83)
我已經改變了代碼位再次加入,似乎除了相機
SpawnSpot[] spawnSpots;
void Start() {
Connect();
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGui(){
Debug.Log ("OnGui" + PhotonNetwork.connectionStateDetailed.ToString());
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
// Update is called once per frame
void OnJoinedLobby() {
Debug.Log ("Joined Lobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("Joined Room");
SpawnMyPlayer();
}
public void SpawnMyPlayer(){
SpawnSpot mySpawnSpot = spawnSpots [ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayer = PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
//standbyCamera.enabled = false;
myPlayer.gameObject.SetActive (true);
//((MonoBehaviour)myPlayer.GetComponent("CharacterController")).enabled = true;
((MonoBehaviour)myPlayer.GetComponent("CharMove")).enabled = true;
Transform[] allChildren = GetComponentsInChildren<Transform>();
foreach (Transform child in allChildren) {
((MonoBehaviour)child.GetComponent("MouseLook")).enabled = true;
child.transform.FindChild("Camera").gameObject.SetActive (true);
}
//myPlayer.transform.FindChild ("Camera").gameObject.SetActive (true);
}
}
當我產卵是工作第二個字符它不啓動相機,並在技術上控制第一個字符相機的第二個字符。
正如我一直在編碼就能伊夫想出這個
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGui(){
Debug.Log ("OnGui" + PhotonNetwork.connectionStateDetailed.ToString());
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
}
// Update is called once per frame
void OnJoinedLobby() {
Debug.Log ("Joined Lobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed(){
Debug.Log ("Failed Join");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("Joined Room");
SpawnMyPlayer();
}
public void SpawnMyPlayer(){
SpawnSpot mySpawnSpot = spawnSpots [ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayer = PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
//standbyCamera.enabled = false;
myPlayer.gameObject.SetActive (true);
//((MonoBehaviour)myPlayer.GetComponent("CharacterController")).enabled = true;
try
{
MouseLook mouseScript = myPlayer.GetComponentInChildren<MouseLook>();
if(mouseScript != null)
{
mouseScript.enabled = true;
}
CharMove moveScript = myPlayer.GetComponentInChildren<CharMove>();
if(moveScript != null)
{
moveScript.enabled = true;
}
CharacterController controlScript = myPlayer.GetComponentInChildren<CharacterController>();
if(controlScript != null)
{
controlScript.enabled = true;
}
Camera childCam = myPlayer.GetComponentInChildren<Camera>();
if(childCam != null)
{
childCam.enabled = true;
}
}
catch
{
Debug.Log ("Error finding children");
}
}
}
所以我沒有得到任何錯誤,但它沒有找到炮塔,PivotPoint的孩子,使其看起來鼠標僅使炮塔鼠標外觀。