- Home /
Spawning Player 2 through network and giving it access to another script
Hey guys, Spawning ive spawned player 2 the right way now, but im having another problem.
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, SpawnPoint1.transform.rotation, 0);
nView = (NetworkView)playerObj.GetComponent("NetworkView");
Debug.Log("Spawned Player 1");
}
else
{
playerObj = (GameObject)Network.Instantiate(playerPrefab2, SpawnPoint2.transform.position, SpawnPoint2.transform.rotation, 1);
transform.position = new Vector3(-1,0,0);
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++;
}
both players spawn from empty gameobjects SpawnPoint1 and SpawnPoint2. player one works fine and the control for the turret is locked like it should be, but spawning player 2 turret is not locking. what have i missed ?
Comment
It's better to have this specific question for your problem, but close your previous question by selecting an answer because it is corrected.