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

A Bug with Photon Multiplayer..

Discussion in 'Scripting' started by BubyMB, Jun 11, 2016.

  1. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Hey guys! Sorry in advance that I have posted recently (I find that taboo)
    I am only new to networking & Multiplayer.
    So I am having a problem with my Photon.. Here is my Game Manager Script...
    This script is held inside my main scene. So I have the hub Scene (Called MainMenu) and a game scene (Called MainGame)
    Code (csharp):
    1. //Game Manager Script
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class GameManager : MonoBehaviour
    6. {
    7.     public GameObject Spawn;
    8.     public Font _32Font;
    9.     public Font _32Font2;
    10.  
    11.     public Font _16Font;
    12.     public Font _16Font2;
    13.  
    14.     void onConnectionFail()
    15.     {
    16.         Application.LoadLevel("MainMenu");
    17.     }
    18.  
    19.     public GameObject standbyCamera;
    20.     int state = 0;
    21.  
    22.     void Start()
    23.     {
    24.  
    25.     }
    26.  
    27.     void OnGUI()
    28.     {
    29.         GUIStyle MainStyle = new GUIStyle();
    30.         MainStyle.font = _32Font;
    31.  
    32.         GUIStyle SecondaryStyle = new GUIStyle();
    33.         SecondaryStyle.font = _16Font;
    34.         switch (state)
    35.         {
    36.             case 0:
    37.                 GUI.Label(new Rect(0, 0, 200, 20), "There are currently " + PhotonNetwork.countOfPlayers + " Players playing", SecondaryStyle);
    38.  
    39.                 if (GUI.Button(new Rect(60, 80, 200, 20), "Akali", MainStyle))
    40.                 {
    41.                     SpawnPlayer("1");
    42.                     state = 1;
    43.                 }
    44.  
    45.                 if (GUI.Button(new Rect(60, 120, 200, 20), "Bloodseeker", MainStyle))
    46.                 {
    47.                    
    48.                 }
    49.  
    50.  
    51.                 break;
    52.             case 1:
    53.                 //InGame
    54.  
    55.                 break;
    56.         }
    57.  
    58.     }
    59.  
    60.     public void SpawnPlayer(string character)
    61.     {
    62.         Vector3 SpawnPos = new Vector3();
    63.         SpawnPos.x = 252;
    64.         SpawnPos.y = 3f;
    65.         SpawnPos.z = 252;
    66.         GameObject myPlayer = PhotonNetwork.Instantiate(character, SpawnPos, transform.rotation, 0);
    67.         myPlayer.transform.position = SpawnPos;
    68.  
    69.         standbyCamera.SetActive(false);
    70.         state = 1;
    71.         SpawnPos.z = SpawnPos.z - 5;
    72.         GameObject mobaCam = PhotonNetwork.Instantiate("MobaCam", SpawnPos, myPlayer.transform.rotation, 0);
    73.         Follow mobaCamScript = mobaCam.GetComponent <Follow>();
    74.         mobaCamScript.player = myPlayer;
    75.  
    76.     }
    77. }
    78.  
    and here is my menu manager; the one inside the lobby/hub/MainMenu
    Code (csharp):
    1. //Menu Manager
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MenuManager : MonoBehaviour
    6. {
    7.  
    8.     public int state = 0;
    9.     public GUIStyle SubText;
    10.     public GUIStyle Header;
    11.     public string Version;
    12.  
    13.     public Font MainFont;
    14.     public Font SecondFont;
    15.  
    16.     public string battleForgeLevelName;
    17.  
    18.  
    19.     void Start()
    20.     {
    21.  
    22.     }
    23.  
    24.     void OnFailedToConnectToPhoton()
    25.     {
    26.         state = 7;
    27.     }
    28.  
    29.     void OnJoinedLobby()
    30.     {
    31.         state = 2;
    32.     }
    33.  
    34.     void OnJoinedLobbyFailed()
    35.     {
    36.         state = 0;
    37.     }
    38.  
    39.     void OnPhotonRandomJoinFailed()
    40.     {
    41.         PhotonNetwork.CreateRoom(null);
    42.     }
    43.  
    44.     void OnJoinedRoom()
    45.     {
    46.         state = 4;
    47.     }
    48.  
    49.     void OnGUI()
    50.     {
    51.         GUIStyle MainStyle = new GUIStyle();
    52.         MainStyle.font = MainFont;
    53.  
    54.         GUIStyle SecondaryStyle = new GUIStyle();
    55.         SecondaryStyle.font = SecondFont;
    56.         switch (state)
    57.         {
    58.             case 0:
    59.                 // MENU
    60.  
    61.                 //GUI.Label(new Rect(10, 10, 200, 30), "Welcome to Shadow's Reach", MainStyle);
    62.                 //GUI.Label(new Rect(10, 30, 200, 30), "Server Status: Online", MainStyle);
    63.                 //GUI.Label(new Rect(10, 50, 200, 30), "Current Version " + Version, MainStyle);
    64.  
    65.  
    66.                     if (GUI.Button(new Rect((Screen.width / 2) - 25, (Screen.height / 2), 100, 30), "Start", MainStyle))
    67.                     {
    68.                         state = 1;
    69.                         PhotonNetwork.ConnectUsingSettings("1.0");
    70.                     }
    71.  
    72.                   if (GUI.Button(new Rect((Screen.width / 2) - 25, (Screen.height / 2) + 25, 100, 30),"Settings" , MainStyle))
    73.                   {
    74.                        state = 6;
    75.                   }
    76.                 break;
    77.  
    78.             case 1:
    79.                 // Connect to Server
    80.  
    81.                 GUI.Label(new Rect((Screen.width / 2) - 75, Screen.height / 2, 100, 40), "Connecting to Server...", MainStyle);
    82.  
    83.                 break;
    84.  
    85.             case 2:
    86.                 if (GUI.Button(new Rect(10, 10, 100, 30), "Back", MainStyle))
    87.                 {
    88.                     state = 0;
    89.                 }
    90.  
    91.                 if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 40, 200, 30), "3V3 - Shadow's Summit", MainStyle))
    92.                 {
    93.                     state = 3;
    94.                     PhotonNetwork.JoinRandomRoom();
    95.                 }
    96.  
    97.                 break;
    98.             case 3:
    99.  
    100.                 GUI.Label(new Rect((Screen.width / 2) - 100, Screen.height / 2, 100, 40), "Searching for Players...", MainStyle);
    101.  
    102.                 break;
    103.             case 4:
    104.                 //Game Found, Waiting for Full Lobby
    105.  
    106.                 if (PhotonNetwork.playerList.Length == 1 & PhotonNetwork.isMasterClient == true)
    107.                 {
    108.                     this.GetComponent<PhotonView>().RPC("StartGame", PhotonTargets.All);
    109.                 }
    110.  
    111.                 break;
    112.             case 5:
    113.                 // In-Game
    114.  
    115.                 break;
    116.             case 6:
    117.                 if (GUI.Button(new Rect(10, 10, 100, 30), "Back", MainStyle))
    118.                 {
    119.                     state = 0;
    120.                 }
    121.                 if (AudioListener.volume == 0  && GUI.Button(new Rect((Screen.width / 2) - 25, 10, 60, 30), "Sound: Off", MainStyle)) {
    122.                     AudioListener.volume = 1;
    123.                 }else if (AudioListener.volume != 0 &&  GUI.Button(new Rect((Screen.width / 2) - 25, 10, 60, 30), "Sound: On", MainStyle))
    124.                 {
    125.                     AudioListener.volume = 0;
    126.                 }
    127.                 break;
    128.             case 7:
    129.                 GUI.Label(new Rect((Screen.width / 2) - 75, Screen.height / 2, 100, 40), "Failed to connect to server..", MainStyle);
    130.                 GUI.Label(new Rect((Screen.width / 2) - 75, (Screen.height / 2) + 25, 100, 40), "Redirecting..", MainStyle);
    131.                 break;
    132.         }
    133.  
    134.     }
    135.  
    136.     [PunRPC]
    137.     public void StartGame()
    138.     {
    139.         state = 5;
    140.         Application.LoadLevel("MainGame");
    141.     }
    142. }
    143.  
    so I am having 2 problems,
    1. When I join the MainGame Scene it says there is 2 audio listeners. I tried removing the audio listener from the camera I am instantiating and move it to another camera in game.

    2. When I join with 2 clients it sends 1 client to the game but glitches the other out and keeps it in the lobby scene when it tries to join, and spawns the player in the lobby. I dont know if it is just that I am using the same pc for two games or what..
     
  2. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,958
    If you're encountering problems with Photon you might have a better chance getting an answer from their official forums.

    http://forum.photonengine.com/