Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Third Party 2d Photon question

Discussion in 'Multiplayer' started by jplegris, Apr 4, 2014.

  1. jplegris

    jplegris

    Joined:
    Nov 16, 2013
    Posts:
    9
    Good day,

    I am currently trying to build a 2D game using photon for multi-player. Right now i create my room and i can join it. and i get an instance that spawns my character when i join a room.
    Code (csharp):
    1.  
    2. using System.Collections;
    3.  
    4. public class NetworkManager : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         Connect();
    9.     }
    10.  
    11.     void Connect(){
    12.         PhotonNetwork.ConnectUsingSettings ("2DMulti V0.0.1");
    13.         }
    14.  
    15.     void OnGUI(){
    16.  
    17.         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
    18.         }
    19.     void OnJoinedLobby(){
    20.  
    21.         PhotonNetwork.JoinRandomRoom ();
    22.     }
    23.  
    24.     void OnPhotonRandomJoinFailed(){
    25.         PhotonNetwork.CreateRoom (null);
    26.         Debug.Log ("createroom");
    27.  
    28.     }
    29.  
    30.     void OnJoinedRoom(){
    31.         SpawnMyPlayer ();
    32.         }
    33.  
    34.     void SpawnMyPlayer(){
    35.     PhotonNetwork.Instantiate ("MyPlayer", Vector3.zero, Quaternion.identity, 0);
    36.  
    37.     }
    38. }
    39.  
    40.  
    41.  
    How can i make my second player that connects(from a different location) appear on the screen too(it works if i do it in 3d)
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,076
    It looks like it should work. Maybe the created GameObject is simply not in the screen?
    Start one client and the game in-Editor. In the Editor, you can check if the Hierarchy gets the "MyPlayer" game object of both players. Check for debug logs in case the game just runs into some exception.
     
  3. jplegris

    jplegris

    Joined:
    Nov 16, 2013
    Posts:
    9
    Thank you very much both instance of the MyPlayer is there when i check in the Hierarchy and if i move one of them in my scene i see both. Now my new question is how come nothing is updated in both instance. If i play my client version, and my character moves i dont see it move in my editor. Nothing is updated.

    Thanks
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,076
    Check the PhotonView component on the prefab. The Observe option might be "off" or maybe it doesn't observe anything.
    In worst case the transform for 2d is actually different than the one in 3d and we can't successfully grab the values from that. I have to admit: I didn't explicitly test 2d game objects.
     
  5. jplegris

    jplegris

    Joined:
    Nov 16, 2013
    Posts:
    9
    Hi,

    i have included the screenshot of the settings i currently have

    To answer your questions :
    No errors in log
    connectionStateDetailed is Joined(If I start my editor before the client i get my debug message that createroom has been executed)
    My movement script works. when everything is running if i manually move my character in the scene view my client will have the change but when my movement script is executed on MyPlayer(Children) the change are not synchronising.
     

    Attached Files:

  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,076
    In that screenshot: Is "MyPlayer" selected? It seems we see "MyPlayer(Clone)" in Inspector?
    I wonder how the setup is when you write "MyPlayer(Children)". Where exactly is the script?
    If it doesn't work with the script but without, then the script will be interesting to see. I'd have a look at a repro project, if you can send one. Mail me to developer@exitgames.com and refer to this topic please. I won't be available before Friday, so please expect a reply next week or so. We're at the Quo Vadis in Berlin this week.