- Home /
Question by
Pootis_Potato · Apr 21, 2016 at 08:12 AM ·
unity 5networking
NetworkServer.spawn NOT WORKING!
My problem is that when I try to spawn the player, it is only able to do so on the client which 'hosted' the game. The error I receive from attempting to spawn the player is, "NetworkServer is not active. Cannot spawn objects without an active server." I'm not sure what is causing this, however, I am also aware that when connected as a 'client' NetworkServer.active equals false.
public GameObject RedNetworkObject;
public GameObject BlueNetworkObject;
// Use this for initialization
void Start () {
if (NetworkServer.active) {
Debug.Log ("Server Is Online");
} else {
Debug.Log ("Server Isn't Online");
}
}
// Update is called once per frame
void Update () {
}
[Command]
void CmdSpawnRed()
{
GameObject ChooseClassObject;
ChooseClassObject = (GameObject)Instantiate (RedNetworkObject, GameObject.Find ("RedSpawnPoint").transform.position, Quaternion.identity);
if (isServer) {
NetworkServer.Spawn (ChooseClassObject);
}
if (isClient) {
NetworkServer.SpawnWithClientAuthority (ChooseClassObject, connectionToClient);
}
}
[Command]
void CmdSpawnBlue ()
{
GameObject ChooseClassObject;
ChooseClassObject = (GameObject)Instantiate (BlueNetworkObject, GameObject.Find ("BlueSpawnPoint").transform.position, Quaternion.identity);
if (isServer) {
NetworkServer.Spawn (ChooseClassObject);
}
if (isClient) {
NetworkServer.SpawnWithClientAuthority (ChooseClassObject, connectionToClient);
}
}
Comment
Your answer