Question by
UDN_9a915d40-27e1-405b-b1cc-83be8be3e71d · Dec 26, 2017 at 06:57 PM ·
multiplayerunity 2dmultiplayer-networking
NetworkServer is not active. Cannot spawn objects without an active server.
Hi! I'm making a 2D Tank game where bullets are fired when you tap an on-screen button. The platform target is mobile.
I have Installed the app on my iPhone 7 and hosted a room. I then go in on the Unity connector and enter my phone's local ip address: 192.168.1.11. No errors and I connect successfully. Both the players are at the correct positions with the correct rotations etc... When I try firing a bullet from my iPhone (the host) it works perfectly without any errors but when I attempt firing a bullet from the client i get this error:
The error points to line 103 where: Network.Spawn(bullet_fired); Here's the relevant part of the script (Tank.cs):
[Command]
void CmdShootBullet() {
if (!isLocalPlayer) {
return;
}
Vector3 pos_offset = new Vector3(0, 0, -3f);
Vector3 bullet_pos = bulletSpawn.transform.position - pos_offset;
GameObject bullet_fired = (GameObject)Instantiate(bullet, bullet_pos, this.transform.rotation);
// Physics2D.IgnoreCollision(bullet_fired.GetComponent<Collider2D>(), this.GetComponent<Collider2D>());
//
// Debug.Log("playerControllerId: " + playerControllerId);
// if (playerControllerId == 0) {
// NetworkServer.SpawnWithClientAuthority(bullet_fired, connectionToClient);
// } else if (playerControllerId > 0) {
// NetworkServer.SpawnWithClientAuthority(bullet_fired, connectionToServer);
// }
NetworkServer.Spawn(bullet_fired);
// Destroy the bullet after 2 seconds
Destroy(bullet_fired, 2.0f);
}
Thanks for any help I can get! I have been debugging this for 2 days and scanned!
screen-shot-2017-12-26-at-171147.png
(16.2 kB)
Comment