Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by SirOrange · Dec 27, 2017 at 04:40 PM · networkinginstantiateprefabphotongeneral

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");
 }


} `

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

137 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges