Search Unity

Third Party Photon Unity Network Tutorial [please help]

Discussion in 'Multiplayer' started by Todokoro, Jul 24, 2017.

  1. Todokoro

    Todokoro

    Joined:
    Feb 1, 2015
    Posts:
    1
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3.  
    4.  
    5. namespace com.example.namespace
    6. {
    7.     public class Launcher : Photon.PunBehaviour
    8.    
    9.     {
    10.         #region Public Variables
    11.        
    12.  
    13.         [Tooltip("The maximum number of players per room. When a room is full, it can't be joined by new players, and so a new room will be created.")]
    14.         public byte MaxPlayersPerRoom = 4;
    15.        
    16.         #endregion
    17.  
    18.  
    19.         #region Private Variables
    20.  
    21.  
    22.  
    23.         string _gameVersion = "1";
    24.  
    25.         #endregion
    26.  
    27.         #region MonoBehaviour CallBacks
    28.  
    29.  
    30.         public PhotonLogLevel Loglevel = PhotonLogLevel.Informational;
    31.  
    32.  
    33.         void Awake()
    34.         {
    35.  
    36.             PhotonNetwork.autoJoinLobby = false;
    37.  
    38.  
    39.             PhotonNetwork.automaticallySyncScene = true;
    40.  
    41.  
    42.             PhotonNetwork.logLevel = Loglevel;
    43.         }
    44.  
    45.         #endregion
    46.  
    47.         #region Public Methods
    48.  
    49.  
    50.         public void Connect()
    51.  
    52.         {
    53.  
    54.  
    55.             {.
    56.                 PhotonNetwork.JoinRandomRoom();
    57.                 progressLabel.SetActive(true);
    58.                 controlPanel.SetActive(false);
    59.  
    60.             }
    61.             else{
    62.                 // #Critical, we must first and foremost connect to Photon Online Server.
    63.                 PhotonNetwork.ConnectUsingSettings(_gameVersion);
    64.                 progressLabel.SetActive(false);
    65.                 controlPanel.SetActive(true);
    66.  
    67.             }
    68.          
    69.         }
    70.  
    71.         [Tooltip("The UI Panel to let the user enter name, connect and play")]
    72.         public GameObject controlPanel;
    73.         [Tooltip("The UI Label to inform the user that the connection is in progress")]
    74.         public GameObject progressLabel;
    75.         #endregion
    76.  
    77.         #region Photon.PunBehaviour CallBacks
    78.  
    79.  
    80.  
    81.  
    82.  
    83.  
    84.         public override void OnConnectedToMaster()
    85.         {
    86.  
    87.             Debug.Log("DemoAnimator/Launcher: OnConnectedToMaster() was called by PUN");
    88.            
    89.             PhotonNetwork.JoinRandomRoom();
    90.  
    91.         }
    92.  
    93.         public override void OnPhotonRandomJoinFailed(object[] codeAndMsg)
    94.         {
    95.             Debug.Log("DemoAnimator/Launcher:OnPhotonRandomJoinFailed() was called by PUN,");
    96.  
    97.  
    98.             PhotonNetwork.CreateRoom(null, new RoomOptions() { MaxPlayers = 4 }, null);
    99.         }
    100.  
    101.         public override void OnJoinedRoom()
    102.         {
    103.             Debug.Log("DemoAnimator/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room.");
    104.         }
    105.  
    106.         public override void OnDisconnectedFromPhoton()
    107.         {
    108.             progressLabel.SetActive(true);
    109.             controlPanel.SetActive(false);
    110.             Debug.LogWarning("DemoAnimator/Launcher: OnDisconnectedFromPhoton() was called by PUN");
    111.            
    112.         }
    113.        
    114.  
    115.         #endregion
    116.  
    117.     }
    118. }
    119.  
    Hi everybody. still new to this forum and to unity. Anywho, I'm on the last part of part 2 on the PUN tutorial found here. I am trying to do the last part where the UI is supposed to show the word "Connecting..." right above my "play" button, but I am having issues getting "Connecting..." to appear when I hit the button. I tried to edit the part where it says:

    Code (CSharp):
    1.  
    2.         {
    3.  
    4.            
    5.             if (PhotonNetwork.connected)
    6.  
    7.             {
    8.                 OnPhotonRandomToinFailed() and we'll create one.
    9.                PhotonNetwork.JoinRandomRoom();
    10.                progressLabel.SetActive(true);
    11.                controlPanel.SetActive(false);
    12.  
    13.            }
    14.            else{
    15.  
    16.                PhotonNetwork.ConnectUsingSettings(_gameVersion);
    17.                progressLabel.SetActive(false);
    18.                controlPanel.SetActive(true);
    19.  
    20.            }
    21.        
    22.        }
    23.  
    I keep on changing the values for "progressLabel.SetActive(false);" & "controlPanel.SetActive(true);" back and forth to "progressLabel.SetActive(true);" & "controlPanel.SetActive(false);" for all of the true/false values, but its not doing what it should which it should say "Connecting..." as soon as I hit the play button, except "Connecting..." stays on the canvas for the UI and then disappears when I click on the play button. Its even more frustrating when the directions on Part 2 of the tutorial says "2. Add the two following properties within the Public Properties Region" when there is no Public Properties region. (second part of the question) What am I supposed to do here since there is no Public Properties region? Is it Public Methods that I am supposed to be adding to? I'm so lost right now.

    Thank you in advance.
     
  2. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    I'm not able to help you directly but I have a Photon Tutorial series that is pretty complete. It may help you out. I'm also taking suggestions of Photon videos to produce should I have missed something. Http://www.youtube.com/c/firstgeargames/

    Please see my Playlist.
     
    Turtled likes this.