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)
//Game Manager Script
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour
{
public GameObject Spawn;
public Font _32Font;
public Font _32Font2;
public Font _16Font;
public Font _16Font2;
void onConnectionFail()
{
Application.LoadLevel("MainMenu");
}
public GameObject standbyCamera;
int state = 0;
void Start()
{
}
void OnGUI()
{
GUIStyle MainStyle = new GUIStyle();
MainStyle.font = _32Font;
GUIStyle SecondaryStyle = new GUIStyle();
SecondaryStyle.font = _16Font;
switch (state)
{
case 0:
GUI.Label(new Rect(0, 0, 200, 20), "There are currently " + PhotonNetwork.countOfPlayers + " Players playing", SecondaryStyle);
if (GUI.Button(new Rect(60, 80, 200, 20), "Akali", MainStyle))
{
SpawnPlayer("1");
state = 1;
}
if (GUI.Button(new Rect(60, 120, 200, 20), "Bloodseeker", MainStyle))
{
}
break;
case 1:
//InGame
break;
}
}
public void SpawnPlayer(string character)
{
Vector3 SpawnPos = new Vector3();
SpawnPos.x = 252;
SpawnPos.y = 3f;
SpawnPos.z = 252;
GameObject myPlayer = PhotonNetwork.Instantiate(character, SpawnPos, transform.rotation, 0);
myPlayer.transform.position = SpawnPos;
standbyCamera.SetActive(false);
state = 1;
SpawnPos.z = SpawnPos.z - 5;
GameObject mobaCam = PhotonNetwork.Instantiate("MobaCam", SpawnPos, myPlayer.transform.rotation, 0);
Follow mobaCamScript = mobaCam.GetComponent <Follow>();
mobaCamScript.player = myPlayer;
}
}
and here is my menu manager; the one inside the lobby/hub/MainMenu
//Menu Manager
using UnityEngine;
using System.Collections;
public class MenuManager : MonoBehaviour
{
public int state = 0;
public GUIStyle SubText;
public GUIStyle Header;
public string Version;
public Font MainFont;
public Font SecondFont;
public string battleForgeLevelName;
void Start()
{
}
void OnFailedToConnectToPhoton()
{
state = 7;
}
void OnJoinedLobby()
{
state = 2;
}
void OnJoinedLobbyFailed()
{
state = 0;
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
}
void OnJoinedRoom()
{
state = 4;
}
void OnGUI()
{
GUIStyle MainStyle = new GUIStyle();
MainStyle.font = MainFont;
GUIStyle SecondaryStyle = new GUIStyle();
SecondaryStyle.font = SecondFont;
switch (state)
{
case 0:
// MENU
//GUI.Label(new Rect(10, 10, 200, 30), "Welcome to Shadow's Reach", MainStyle);
//GUI.Label(new Rect(10, 30, 200, 30), "Server Status: Online", MainStyle);
//GUI.Label(new Rect(10, 50, 200, 30), "Current Version " + Version, MainStyle);
if (GUI.Button(new Rect((Screen.width / 2) - 25, (Screen.height / 2), 100, 30), "Start", MainStyle))
{
state = 1;
PhotonNetwork.ConnectUsingSettings("1.0");
}
if (GUI.Button(new Rect((Screen.width / 2) - 25, (Screen.height / 2) + 25, 100, 30),"Settings" , MainStyle))
{
state = 6;
}
break;
case 1:
// Connect to Server
GUI.Label(new Rect((Screen.width / 2) - 75, Screen.height / 2, 100, 40), "Connecting to Server...", MainStyle);
break;
case 2:
if (GUI.Button(new Rect(10, 10, 100, 30), "Back", MainStyle))
{
state = 0;
}
if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 40, 200, 30), "3V3 - Shadow's Summit", MainStyle))
{
state = 3;
PhotonNetwork.JoinRandomRoom();
}
break;
case 3:
GUI.Label(new Rect((Screen.width / 2) - 100, Screen.height / 2, 100, 40), "Searching for Players...", MainStyle);
break;
case 4:
//Game Found, Waiting for Full Lobby
if (PhotonNetwork.playerList.Length == 1 & PhotonNetwork.isMasterClient == true)
{
this.GetComponent<PhotonView>().RPC("StartGame", PhotonTargets.All);
}
break;
case 5:
// In-Game
break;
case 6:
if (GUI.Button(new Rect(10, 10, 100, 30), "Back", MainStyle))
{
state = 0;
}
if (AudioListener.volume == 0 && GUI.Button(new Rect((Screen.width / 2) - 25, 10, 60, 30), "Sound: Off", MainStyle)) {
AudioListener.volume = 1;
}else if (AudioListener.volume != 0 && GUI.Button(new Rect((Screen.width / 2) - 25, 10, 60, 30), "Sound: On", MainStyle))
{
AudioListener.volume = 0;
}
break;
case 7:
GUI.Label(new Rect((Screen.width / 2) - 75, Screen.height / 2, 100, 40), "Failed to connect to server..", MainStyle);
GUI.Label(new Rect((Screen.width / 2) - 75, (Screen.height / 2) + 25, 100, 40), "Redirecting..", MainStyle);
break;
}
}
[PunRPC]
public void StartGame()
{
state = 5;
Application.LoadLevel("MainGame");
}
}
so I am having 2 problems,
-
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.
-
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…