- Home /
Spawning Clients
I make a multiplayer game with max 4 Players (1 Server + 3 Clients). I have four different spawn-positions. The Server takes the first spawn-position. The first Client shoult take the next spawn-position, the seceond client the next spawn-position, etc. With my code, all Clients spawn at the first postion. Why?
 [System.Serializable]
 public class SpawnPoint
 {
     SpawnPoint()
     {
         isAvailable = true;
     }
 
     public Transform transform;
     public GameObject playerPrefab;
     public bool isAvailable;
 }
 
 public class SpawnManager : MonoBehaviour
 {
     public SpawnPoint[] spawnPoint = new SpawnPoint[4];
 
     private int m_playerCount = 0;
 
     void OnServerInitialized()
     {
         Network.Instantiate(spawnPoint[0].playerPrefab, spawnPoint[0].transform.position, spawnPoint[0].transform.rotation, 0);
         spawnPoint[0].isAvailable = false;
     }
 
     void OnPlayerConnected(NetworkPlayer player)
     {
         networkView.RPC("PlayerCount", RPCMode.Others, Network.connections.Length);
     }
 
     void OnConnectedToServer()
     {
         SpawnPlayer(m_playerCount);
     }
 
     void SpawnPlayer(int index)
     {
         Network.Instantiate(spawnPoint[index].playerPrefab, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0);
     }
 
     [RPC]
     void PlayerCount(int value)
     {
         m_playerCount = value;
     }
 }
Is your syntax on line 28 correct? You have networkView the doc shows it as NetworkView - I don't know multiplayer stuff so that might be irrelevant.
That should be fine. NetworkView is the data type. networkView is the variable form type NetworkView. I think the Problem is, that the Client is Spawning before he(it? sorry my english sucks) get the Information from the RPC call.
Answer by 5114fu · Sep 10, 2013 at 10:18 AM
Solved it without RPC call:
[System.Serializable] public class SpawnPoint { SpawnPoint() { isAvailable = true; }
 public Transform transform;
 public GameObject playerPrefab;
 public bool isAvailable;
}
public class SpawnManager : MonoBehaviour { public SpawnPoint[] spawnPoint = new SpawnPoint[4];
 private int m_playerCount = 0;
 void OnServerInitialized()
 {
     Network.Instantiate(spawnPoint[0].playerPrefab, spawnPoint[0].transform.position, spawnPoint[0].transform.rotation, 0);
     spawnPoint[0].isAvailable = false;
 }
 void OnConnectedToServer()
 {
     SpawnPlayer(int.Parse(Network.player.ToString()));
 }
 void SpawnPlayer(int index)
 {
     Network.Instantiate(spawnPoint[index].playerPrefab, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0);
 }
}
Your answer
 
 
             Follow this Question
Related Questions
RPC is called but it doesn't destroy some GameObject instances 1 Answer
RPC Call Mix Up Issues 0 Answers
Deleteing Objects created by Clients 0 Answers
Get RPC senders ID, or IP? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                