Unity MonoBehaviourPun and MonoBehaviourPunCallBacks not working

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Unity MonoBehaviourPun and MonoBehaviourPunCallBacks not working

donotprikel
2023-03-02 05:11:47

On unity 2020.3.44f1 i did install photon pun 2 and when i went to code a script for it then when i finnished it i got this error.

Assets\Scripts\Lobby\LobbyManager.cs(6,36): error CS0234: The type or namespace name 'MonoBehaviourPun' does not exist in the namespace 'Photon' (are you missing an assembly reference?)

I have used the MonoBehaviourPun in the public class And i have re imported the entire project then the library folder then the ScriptAssemblies folder Now i lost the Assembly-C#.dll file from that. Nothing worked. I even re downloaded and imported the package from the package manager. When i import it it says all assets from this package are already in your project. Nothing to import. It only shows Pun 2 package in the my assets sction of the package manager. But not the in project. I have literly ran out of options on how to fix it. I cant find specific fix for it online. My assistant keeps telling me to download the unity package from the photon web site but it onlys redirects me to the unity asset store. Do you know how to fix it?

this is the code is it wrong?

using System.Collections.Generic;    
using System.Collections;    
using Photon.Realtime;    
using UnityEngine.UI;    
using UnityEngine;    
using TMPro;    


public class CreateRoom : MonoBehaviourPun    
{    
    [SerializeField]    
    private TMPro.TextMeshProUGUI _roomName;    


        
    public void OnClick_CreateRoom()    
    {    
        RoomOptions options = new RoomOptions();    
        options.MaxPlayers = 4;    
        PhotonNetwork.JoinOrCreateRoom(_roomName.text, options, TypedLobby.Default);    

    }    

    public override void OnCreatedRoom()    
    {    
        MasterManager.DebugConsole.AddText("Room Created successfully", this);    
    }    

    public override void OnCreateRoomFailed(short returnCode, string message)    
    {    
        MasterManager.DebugConsole.AddText("Room Faled to create; " + message, this);    
    }    
}    

Comments

Tobias
2023-03-03 12:24:56

You need these using lines:

using Photon.Pun;    
using Photon.Realtime;    
using UnityEngine;    
Back to top