2014-09-03 3 views
1

여기에는 해결 된 코드가 나와 있습니다.PhotonNetworking 유니티 플레이어 스폰 네트워크가 작동하지 않음

은 []

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"); 
     } 



    } 
} 

그래서 나는 우리가 나는 플레이어의 구조의 이미지와 그와 관련된 스크립트를 첨부 광자 네트워킹을 사용하는에 유니티 프로젝트 메신저가 작동이 해결했다. 어떤 이유로 두 선수를로드 할 때 서로를 볼 수 없습니다.

플레이어를 비활성화하지 않으면 컨트롤이 모두 엉망이되지만 캐릭터의 각 요소와 관련된 스크립트를 사용하지 않도록 설정하고 튜토리얼처럼 문자를 사용하도록 설정하면 어떤 이유로 든 스크립트를 선택할 수 없다는 말로 구성 요소를 얻는 방법을 알 수 없습니다. 나는 실패합니까 enter image description here

여기에 콘솔에 참여하면 출력

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) 

내 네트워크 매니저입니다

/* 
    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의 아이를 발견하고 마우스 그것은 단지 수 있습니다 보면 사용하지 않습니다 터렛 마우스 모습.

답변

0

난 당신이

GameObject myPlayer = PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0); 

는 편집기에서 또한

GameObject myPlayer = (GameObject)PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0); 

이는 데 도움이 Photon View 구성 요소 : 희망을 추가하려고 할 수 있습니다 설정 SpawnMyPlayer 기능에있는 답변을!

관련 문제