- Home /
Question by
Mint92 · Apr 07, 2014 at 01:19 AM ·
c#instantiatenetworkspawningnetworkview
Player 2 not spawning
hey guys, im not sure why player 2 is not spawning properly. abit confused.
public void spawnPlayer()
{
GameObject playerObj = null;
NetworkView nView = null;
// note: Network.Instantiate is a buffered call
if (playerID == 0)
{
playerObj = (GameObject)Network.Instantiate(playerPrefab, spawnPoint1.transform.position, Quaternion.identity, playerID);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 1");
}
else
{
playerObj = (GameObject)Network.Instantiate(playerPrefab2, spawnPoint2.transform.position, Quaternion.identity, playerID);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 2");
}
if (Network.peerType == NetworkPeerType.Server)
{
Debug.Log("Server spawning player" + Network.player);
}
else
{
networkView.RPC("Log", RPCMode.Server, "Client spawning player" + Network.player);
}
nView.RPC("SetOwner", RPCMode.AllBuffered, Network.player);
playerID++;
playerCount++;
}
ive linked the spawn points and prefabs in my network manager object and nothing appears.
Comment
Do you run both Client in an Editor? I had issues when i ran the server as compiled game and the client in the Editor.
Answer by Mint92 · Apr 11, 2014 at 12:08 PM
ive fixed it, they way i was spawning player 2 was crashing my game
public void spawnPlayer()
{
GameObject playerObj = null;
NetworkView nView = null;
// note: Network.Instantiate is a buffered call
if (Network.peerType == NetworkPeerType.Server)
{
playerObj = (GameObject)Network.Instantiate(playerPrefab, SpawnPoint1.transform.position, Quaternion.identity, 0);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 1");
}
else
{
playerObj = (GameObject)Network.Instantiate(playerPrefab2, SpawnPoint2.transform.position, Quaternion.identity, 1);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 2");
}
if (Network.peerType == NetworkPeerType.Server)
{
Debug.Log("Server spawning player" + Network.player);
}
else
{
networkView.RPC("Log", RPCMode.Server, "Client spawning player" + Network.player);
}
nView.RPC("SetOwner", RPCMode.AllBuffered, Network.player);
playerID++;
playerCount++;
}
this solves my problem :)