I get an error message every time i run this script? Any ideas?
This is the error message and it's causing me no not be able to build the game itself. Failed to Instantiate prefab: Sean. Client should be in a room. Current connectionStateDetailed: Authenticating UnityEngine.Debug:LogError(Object) PhotonNetwork:Instantiate(String, Vector3, Quaternion, Byte, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2449) PhotonNetwork:Instantiate(String, Vector3, Quaternion, Byte) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2432) NetWorkmanager:SpawnMyPlayer(Int32) (at Assets/Scripts/NetWorkmanager.cs:165) NetWorkmanager:OnGUI() (at Assets/Scripts/NetWorkmanager.cs:131)
Here's the code:`
public class NetWorkmanager : MonoBehaviour { public static bool connecting = false; List chatMessages; int maxChatMessages = 5; public static GameObject Standby; public string stringToEdit = string.Empty; public static GameObject StandbyCam; bool hasPickedTeam = false; int teamID = 0; // Use this for initialization void Start () {
Standby = GameObject.Find ("Main");
StandbyCam = GameObject.Find ("~WaitingCamera");
PhotonNetwork.player.NickName = PlayerPrefs.GetString ("Username", "Type Here");;
chatMessages = new List<string>();
Standby.SetActive (true);
StandbyCam.SetActive (true);
InvokeRepeating ("Update", 0f, 1.0f);
}
void OnDestroy (){
PlayerPrefs.SetString ("Username", PhotonNetwork.player.NickName);
}
public void AddChatMessage(string m)
{
GetComponent<PhotonView> ().RPC ("AddChatMessage_RPC", PhotonTargets.AllBuffered, m);
}
[PunRPC]
void AddChatMessage_RPC(string m)
{
chatMessages.Add (m);
while (chatMessages.Count >= maxChatMessages)
{
chatMessages.RemoveAt (0);
}
}
public void AddlocalMessage(string m)
{
chatMessages.Add (m);
while (chatMessages.Count >= maxChatMessages)
{
chatMessages.RemoveAt (0);
}
}
void Update(){
}
void Connect (){
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
public void OnGUI()
{
if (GUILayout.Button ("Plans"))
{
AddlocalMessage ("Current Plan: " + currentQuest);
}
if (PhotonNetwork.connected == true && connecting == false) {
GUILayout.BeginHorizontal (GUILayout.MaxWidth(250));
stringToEdit = GUI.TextField (new Rect(0, 889, 200, 20), stringToEdit, 50);
if (GUI.Button(new Rect(201, 889, 75, 20), "Send"))
{
if (!string.IsNullOrEmpty (stringToEdit.Trim ())) {
AddChatMessage (PhotonNetwork.player.NickName + ": " + stringToEdit);
stringToEdit = string.Empty;
}
}
GUILayout.EndHorizontal ();
}
if (PhotonNetwork.connected == false && connecting == false) {
//GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
//GUILayout.BeginHorizontal();
//GUILayout.FlexibleSpace();
//GUILayout.BeginVertical();
//GUILayout.FlexibleSpace ();
//GUILayout.BeginHorizontal();
//GUILayout.Label ("Username: ");
//PhotonNetwork.player.NickName = GUILayout.TextField (PhotonNetwork.player.NickName);
//GUILayout.EndHorizontal();
//GUILayout.FlexibleSpace();
//GUILayout.EndVertical();
//GUILayout.FlexibleSpace();
//GUILayout.EndHorizontal ();
//GUILayout.EndArea ();
}
if (PhotonNetwork.connected == true && connecting == false) {
if (hasPickedTeam) {
GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height));
GUILayout.BeginVertical ();
GUILayout.FlexibleSpace ();
foreach (string msg in chatMessages) {
GUILayout.Label (msg);
}
GUILayout.EndVertical ();
GUILayout.EndArea ();
}
else {
SpawnMyPlayer (Random.Range (1, 2));
}
}
}
void OnJoinedLobby(){
Debug.Log ("Joinedlobby");
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed(){
PhotonNetwork.CreateRoom (null);
Debug.Log ("creatingroom");
}
void OnJoinedRoom(){
Debug.Log ("joinedroom");
connecting = false;
SpawnMyPlayer(teamID);
}
void Loadlevel(){
connecting = true;
Connect ();
}
void SpawnMyPlayer(int teamID){
this.teamID = teamID;
hasPickedTeam = true;
Standby.SetActive (false);
StandbyCam.SetActive (false);
AddChatMessage ("Spawning player: " + PhotonNetwork.player.NickName);
if (teamID == 1 ) {
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("Sean", Vector3.zero, Quaternion.identity, 0);
myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
myPlayerGO.GetComponent<TemporaryMove> ().enabled = true;
myPlayerGO.GetComponent<NetworkCharacter> ().enabled = true;
myPlayerGO.GetComponent<TeamMember> ().teamID = teamID;
myPlayerGO.GetComponent<WeaponPickup> ().enabled = true;
}
if (teamID == 2) {
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("SeanB", Vector3.zero, Quaternion.identity, 0);
myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
myPlayerGO.GetComponent<TemporaryMove> ().enabled = true;
myPlayerGO.GetComponent<NetworkCharacter> ().enabled = true;
myPlayerGO.GetComponent<TeamMember> ().teamID = teamID;
}
if (teamID == 3) {
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("SeanCom", Vector3.zero, Quaternion.identity, 0);
myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
myPlayerGO.GetComponent<TemporaryMove> ().enabled = true;
myPlayerGO.GetComponent<NetworkCharacter> ().enabled = true;
myPlayerGO.GetComponent<TeamMember> ().teamID = teamID;
}
if (teamID == 4) {
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("SeanO" , Vector3.zero, Quaternion.identity, 0);
myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
myPlayerGO.GetComponent<TemporaryMove> ().enabled = true;
myPlayerGO.GetComponent<NetworkCharacter> ().enabled = true;
myPlayerGO.GetComponent<TeamMember> ().teamID = teamID;
}
}
void OnPlayerDisconnected(){
AddChatMessage (PhotonNetwork.player.NickName + "Has Disconnected");
}
public void onspawnItem() {
Vector3 itemSpawnLocations = new Vector3 (Random.Range(-25, 25), Random.Range (-12.5f, 12.5f), 0);
PhotonNetwork.Instantiate ("Gun1", itemSpawnLocations, Quaternion.identity, 0);
Debug.Log ("Item Spawned");
}
} `
Your answer
Follow this Question
Related Questions
Unity [PUN] New Instantiated players cannot see previously instantiated players 0 Answers
Why is Photon player being instantiated twice? 0 Answers
i can't see other player with photon cloud server,I Can't see each other player in photon cloud 2 Answers
Keeping an object in a multiplayer scene, when a player joins. 3 Answers
C# Photon Networking - Preventing duplicate GameObjects from spawning on Join. 1 Answer