So here is my problem :
I have a small multiplayer project (working with LAN, nothing too fancy), and I’m trying to make the players shoot bullets. On the host, everything works fine. However, it doesn’t work on the cllient. I get this error on the client :
Trying to send command for object without authority.
UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
PlayerController:CallCmdShoot()
PlayerController:FixedUpdate() (at Assets/Scripts/PlayerController.cs:37)
Here is the function calling the command :
void FixedUpdate(){
Move();
if (Input.GetAxis("Fire1")>0.0f && isCooldownOver){
isCooldownOver = false;
CmdShoot();
StartCoroutine(Cooldown());
}
}
With CmdShoot being the said command. Here is the code of that command :
[Command]
void CmdShoot(){
var bullet = (GameObject)Instantiate(bulletPrefab, transform.position + new Vector3(0.0f, 0.0f, 0.5f), transform.rotation);
Destroy(bullet, bulletLife);
NetworkServer.Spawn(bullet);
}
To spawn the player, I use NetworkManager.singleton.StartClient();
inside a CustomNetworkManager script. Below are screenshots of the inspector of the Player prefab and the Bullet prefab.
On the NetworkManager game object, the Bullet is under the Registered Spawnable Prefabs, and the Player prefab is under Player Prefab.
Thanks in advance for your help.