Search Unity

Third Party PUN 2 player networking problem

Discussion in 'Multiplayer' started by luckie12, Oct 15, 2016.

  1. luckie12

    luckie12

    Joined:
    Aug 17, 2014
    Posts:
    165
    Hi!

    I am using Photon Unity Networking engine, but everytime when i spawn in, on both screens, i can control them both on one screen...

    Like if i move on my first screen it also moves the other player...

    i have no idea why, but this is my instantiate code:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class NetworkManager : MonoBehaviour {
    6.  
    7.     const string VERSION = "v0.0.1";
    8.     public string roomName = "Room1";
    9.     public string playerPrefabName = "Cube";
    10.     public GameObject spawnPoint;
    11.  
    12.     // Use this for initialization
    13.     void Start () {
    14.         PhotonNetwork.ConnectUsingSettings(VERSION);
    15.     }
    16.  
    17.     void OnJoinedLobby()
    18.     {
    19.         RoomOptions roomOptions = new RoomOptions() { IsVisible = false, MaxPlayers = 10 };
    20.         PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
    21.     }
    22.  
    23.     void OnJoinedRoom()
    24.     {
    25.         PhotonNetwork.Instantiate(playerPrefabName, spawnPoint.transform.position, spawnPoint.transform.rotation, 0);
    26.     }
    27. }
    28.  
    This is how i decide if it is mine:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class NetworkPlayer : Photon.MonoBehaviour{
    6.     public GameObject myCamera;
    7.     // Use this for initialization
    8.     void Start () {
    9.         if (photonView.isMine)
    10.         {
    11.             myCamera.SetActive(true);
    12.             GetComponent<CharacterController>().enabled = true;
    13.         }
    14.         else
    15.         {
    16.  
    17.         }
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update () {
    22.  
    23.     }
    24. }
    25.  
    I have no errors at all, just some weird playing.



    Thanks guys!



    EDIT:


    I fixed the movement by using this:


    Code (csharp):
    1.  
    2.    if(GetComponent<PhotonView>().isMine)
    3.  
    But the rotation still copys the other player



    EDIT 2:
    Disable the Camera, Controller and the script
    For people having this problem, i fixed it this way:


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class NetworkPlayer : Photon.MonoBehaviour{
    6.     //public GameObject myCamera;
    7.     // Use this for initialization
    8.     void Start () {
    9.         if (GetComponent<PhotonView>().isMine)
    10.         {
    11.             GetComponent<Camera>().enabled = true;
    12.             GetComponent<Look>().enabled = true;
    13.             GetComponent<CharacterController>().enabled = true;
    14.         }
    15.         else
    16.         {
    17.  
    18.         }
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update () {
    23.  
    24.     }
    25. }
    26.  
     
    Last edited: Oct 16, 2016
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
  3. luckie12

    luckie12

    Joined:
    Aug 17, 2014
    Posts:
    165
    Thanks!