Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon pun 2 not working with Photon.PunBehaviour

Discussion in 'Multiplayer' started by donotprikel, Feb 26, 2023.

  1. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    26
    On unity 2020.3.44f1 i have installed photon pun 2 and when i went to script a script for it and finnished it i got this error.
    Assets\Scripts\Lobby\LobbyManager.cs(6,36): error CS0234: The type or namespace name 'PunBehaviour' does not exist in the namespace 'Photon' (are you missing an assembly reference?)
    I have used the Photon.PunBehaviour 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?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5.  
    6. public class LobbyManager : Photon.PunBehaviour
    7. {
    8.  
    9.     string GameVersion = '1';
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         if (!PhotonNetwork.connected)
    15.         {
    16.             PhotonNetwork.autoJoinLobby = false;
    17.  
    18.             PhotonNetwork.automaticallySyncScene = true;
    19.  
    20.             PhotonNetwork.ConnectUsingSettings(GameVersion);
    21.         }
    22.     }
    23.  
    24.     public override void OnConnectedToMaster()
    25.     {
    26.         print("Connected to Master");
    27.         PhotonNectwork.JoinLobby();
    28.     }
    29.  
    30.     public override void OnJoinedLobby()
    31.     {
    32.         print("Connected to Lobby");
    33.     }
    34. }
    35.  
     

    Attached Files:

    Last edited: Feb 26, 2023
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Have you checked that you haven't inadvertently got another class or Namespace called Photon in your project?
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Did you import the package? Check if this folder (among others) exists: Assets\Photon\PhotonUnityNetworking.
    Sometimes it is necessary to force Unity to re generate the project files. You could delete the Library folder and the *.csproj and *.sln files (those should all just be generated by Unity, so they are not even in Version Control most likely).
     
  4. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    26
    Yes i did and i only had like 3 scripts that ive created and none of them have the same names
     
  5. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    26
    If you did not see i alredy imported the package from the package manager. Also even from the asset store. I just dont get why it always works for others and not me.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    I don't know where you got that code but since a while, PUN 2 uses MonoBehaviourPun and MonoBehaviourPunCallbacks. Maybe you copied this from an outdated tutorial?
    Hope you found that already.
     
  7. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    26
    Ive tried both thoes and they dont work im TELLING you i have everything thats requierd is installed. I DONT GET HOW it works for others but not me out of all the people in the world it has to be me.
    An error =
    Assets\Scripts\Lobby\Rooms\CreateRoom.cs(9,27): error CS0246: The type or namespace name 'MonoBehaviourPun' could not be found (are you missing a using directive or an assembly reference?)
     
  8. donotprikel

    donotprikel

    Joined:
    Nov 14, 2022
    Posts:
    26
    I just fiquerd it out you had to add
    using Photon.Realtime; at the top
     
    Munchy2007 likes this.