Search Unity

Connection Issue

Discussion in 'Multiplayer' started by SteamGear, Apr 18, 2014.

  1. SteamGear

    SteamGear

    Joined:
    Apr 18, 2014
    Posts:
    5
    Hello, this is my first attempt to code a multiplayer game, but all players that try to join the game get in different rooms, what did i do wrong?
    Code (csharp):
    1.  
    2. public class Network : Photon.MonoBehaviour{
    3.     void Start () {
    4.         PhotonNetwork.ConnectUsingSettings("test");
    5.     }
    6.  
    7.     void OnGUI () {
    8.         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
    9.         GUILayout.Label("Ping: " + PhotonNetwork.GetPing());
    10.     }
    11.     void OnJoinedLobby()
    12.     {        
    13.         PhotonNetwork.JoinRandomRoom();
    14.     }
    15.     void OnPhotonRandomJoinFailed()
    16.     {
    17.         PhotonNetwork.CreateRoom(null);
    18.     }
    19.     void OnJoinedRoom()
    20.     {
    21.  
    22.         if(GameObject.Find("plate1").GetComponent<Controls>().selected==false)
    23.         {
    24.             GameObject.Find("plate1").GetComponent<Controls>().plate=GameObject.Find ("plate1");
    25.             GameObject.Find("plate1").GetComponent<Controls>().selected=true;
    26.         }
    27.             else
    28.         {
    29.             GameObject.Find("plate2").GetComponent<Controls>().plate=GameObject.Find ("plate2");
    30.             GameObject.Find("plate2").GetComponent<Controls>().selected=true;
    31.  
    32.         }
    33.         if(GameObject.Find("plate2").GetComponent<Controls>().selected==true&GameObject.Find("plate1").GetComponent<Controls>().selected==true)
    34.             {
    35.                 GameObject.Find("Ball").GetComponent<ballmove>().start = true;
    36.             }
    37.     }
    38. }
     
  2. SteamGear

    SteamGear

    Joined:
    Apr 18, 2014
    Posts:
    5
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Cool.
    How did you fix it?
     
  4. SteamGear

    SteamGear

    Joined:
    Apr 18, 2014
    Posts:
    5
    Got rid of useless stuff and it worked :)
    guess the create room settings changed it though :)
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NetworkManager : Photon.MonoBehaviour {
    5.  
    6.     void OnJoinedLobby() {
    7.         PhotonNetwork.JoinRandomRoom();
    8.     }
    9.  
    10.     void OnPhotonRandomJoinFailed() {
    11.         PhotonNetwork.CreateRoom(null,new RoomOptions() {maxPlayers = 2},null);
    12.     }
    13.    
    14.     void OnJoinedRoom() {
    15.        
    16.             Vector3 spawn = new Vector3 (7.5f,0f,0f);
    17.             GameObject npl = PhotonNetwork.Instantiate("plate1",spawn,Quaternion.identity,0);
    18.  
    19.             npl.GetComponent<Controls>().plate=npl;
    20.             npl.GetComponent<Controls>().selected=true;
    21.         }
    22.        
    23.  
    24.  
    25.     }
    26.    
    27. }