Unity, Photon; Why do I have to declare "using Photon.Realtime" in my c# code?


I’m trying to make a game using Photon PUN in Unity. I am following a tutorial where the following c# code is used in a script file called NetworkManager:

using System.Collections;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {
    //const string VERSION = "v.0.0.1";

	void Start () {

    void OnJoinedLobby()
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.IsVisible = false;
        roomOptions.MaxPlayers = 4;
        PhotonNetwork.JoinOrCreateRoom("Room1", roomOptions, TypedLobby.Default);


My problem is that I get an error saying that “RoomOptions” and “PhotonNetwork” do not exist. I can solve the problem by declaring “using Photon.Realtime” and “using Photon.Pun”, which is fine but it makes me wonder if I have installed PUN incorrectly in Unity because in the tutorial I am following it appears you don’t have to do this (and the same seems to be true in code examples I find in the official documentation. Another difference is that ConnectUsingSettings should require a string argument but when I use it, it says it requires no arguments so I have had to remove the VERSION string.

Thanks in advance for any help.


as an example in terms of PhotonNetwork: you can add using Photon.Pun; to directly use the PhotonNetwork class. If you only have using Photon;, you would have to use Pun.PhotonNetwork each time you want to access the PhotonNetwork class. The same applies for PhotonRealtime and everything else, for example UnityEngine and UnityEngine.UI.

In terms of ConnectUsingSettings: in PUN Classic this function requires a string parameter, the gameVersion. In PUN 2 the signature has changed, so that it doesn’t requires this parameter any longer. You are probably looking at an outdated or PUN Classic specific tutorial.