0
\$\begingroup\$

I am currently making a multiplayer game however only the host has the capability to spawn projectiles.

[Command]
void CmdSpawnEgg()
{
    if (cam == null)
    {
        return;
    }
    GameObject instance = Instantiate(eggPrefab, transform.position + (transform.forward * offset), cam.rotation);
    NetworkServer.Spawn(instance);
}

//cam is the transform of the players camera and if its not the local player the camera is destroyed

these are the settings for the network identity:

The projectile is also a registered spawn-able prefab for the network manager

\$\endgroup\$
  • \$\begingroup\$ Try checking if cam is null on your client player. Or just check for isLocalPlayer \$\endgroup\$ – TehMightyPotato Mar 14 '19 at 9:35
  • \$\begingroup\$ this was the problem i was destroying the camera if it wasnt the local player but that made the server unsure of where the bullet was supposed to come from \$\endgroup\$ – Omari Lawrence Mar 14 '19 at 18:51
  • \$\begingroup\$ nice! glad you figured it out. \$\endgroup\$ – TehMightyPotato Mar 15 '19 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.