Unity Unet Spawning from client

I scripted this code in c#:

using UnityEngine; 
using System.Collections; 
using UnityEngine.Networking; 

class EnemySpawnClient : NetworkBehaviour{ 

public GameObject TankPref;
 [Command] 
void CmdTankFire () { 
if (!isLocalPlayer) 
return; 
GameObject Tank = (GameObject) Instantiate (TankPref, transform.position, transform.rotation); 
NetworkServer.Spawn (Tank);
 } 
}

Now my problem is that when I call the function “CmdTankFire” as a client the GameObject “TankPref” dosnt spawn on the server and on the client (It dosent spawn at all). But when I call this function as a host it spawns on the client and on the server (both). So my question is how can I edit this script so I can spawn the “TankPref” as a client too;

Thanks in advance.

Ps: I attached the script to the Client Player and to the Server Player

you should not have a isLocalPlayer check in the command function.

1 Like

The command runs on the server, so when your client calls it, isLocalPlayer will always be false. That sort of check should be run before calling the command.