This probably a simple error. I followed the tutorial and had compile errors.

Options
I tried this twice. Typing manually first and then copy and pasting:
using UnityEngine;
using Photon.Pun;

namespace Com.MyCompany.MyGame
{
    public class Launcher : MonoBehaviourPunCallbacks
    {
        #region Private Serializable Fields

        [Tooltip("The maximum number of players per room. When a room is full, it can't be joined by new players, and so new room will be created")]
        [SerializeField]
        private byte maxPlayersPerRoom = 4;



        #endregion


        #region Private Fields


        /// <summary>
        /// This client's version number. Users are separated from each other by gameVersion (which allows you to make breaking changes).
        /// </summary>
        string gameVersion = "1";

        #endregion
        
        #region MonoBehaviour CallBacks
        
        /// <summary>
        /// MonoBehaviour method called on GameObject by Unity during early initialization phase.
        /// </summary>
        void Awake()
        {
            // #Critical
            // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
            PhotonNetwork.AutomaticallySyncScene = true;
        }


        /// <summary>
        /// MonoBehaviour method called on GameObject by Unity during initialization phase.
        /// </summary>
        void Start()
        {
            Connect();
        }


        #endregion


        #region Public Methods


        /// <summary>
        /// Start the connection process.
        /// - If already connected, we attempt joining a random room
        /// - if not yet connected, Connect this application instance to Photon Cloud Network
        /// </summary>
        public void Connect()
        {
            // we check if we are connected or not, we join if we are , else we initiate the connection to the server.
            if (PhotonNetwork.IsConnected)
            {
                // #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnJoinRandomFailed() and we'll create one.
                PhotonNetwork.JoinRandomRoom();
            }
            else
            {
                // #Critical, we must first and foremost connect to Photon Online Server.
                PhotonNetwork.ConnectUsingSettings();
                PhotonNetwork.GameVersion = gameVersion;
            }
        }


        #endregion

        #region MonoBehaviourPunCallbacks Callbacks


        public override void OnConnectedToMaster()
        {
            Debug.Log("PUN Basics Tutorial/Launcher: OnConnectedToMaster() was called by PUN");
            PhotonNetwork.JoinRandomRoom();
        }

//LINE 90 \/
        public override void OnDisconnected(DisconnectCause cause)
        {
            Debug.LogWarningFormat("PUN Basics Tutorial/Launcher: OnDisconnected() was called by PUN with reason {0}", cause);
        }
        

        public override void OnJoinRandomFailed(short returnCode, string message)
        {
            Debug.Log("PUN Basics Tutorial/Launcher:OnJoinRandomFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom");



            // #Critical: we failed to join a random room, maybe none exists or they are all full. No worries, we create a new room.
//LINE 103 \/
            PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayersPerRoom });
        }

        public override void OnJoinedRoom()
        {
            Debug.Log("PUN Basics Tutorial/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room.");
        }

        #endregion
    }
}

this produced the following errors:

Error CS0115 'Launcher.OnDisconnected(DisconnectCause)': no suitable method found to override Assembly-CSharp
On line 90

Error CS0246 The type or namespace name 'DisconnectCause' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp
On line 90

Error CS0246 The type or namespace name 'RoomOptions' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp
On line 103

I've dropped comments in for ease of reading.

Anyone with any ideas for the novice (me)?

Thanks in advance!

Comments

  • Beep
    Options
    The issue linking those errors is that they don't have access to the underlying types/methods. To solve that you just need to add this at the top:
    using Photon.Realtime;
    
  • Tobias
    Tobias admin
    edited February 2022
    Options

    There were some Unity versions that did not generate correct VS project files.

    Check your Package Manager, if there is a newer version of the Visual Studio integration package (or the same for Rider, etc). If that doesn't help, you may need to update Unity (we don't support the beta).

    Make sure the PUN packages works on import and compile before you change anything. In doubt, create a new, empty project and import. Also, there were a few versions of Unity, which didn't download the Asset Store packages correctly. Make sure you got v2.40.