- Home /
Commands and ClientRPC are not running when called
So in this code, local take damage is printed so that means it is trying to call the command and clientRPC, but neither RPC or CMD damage called is being printed, so none of that code is executing, I have no idea why ;(
public void takedamage(NetworkIdentity rover)
{
print ("Local take damage called");
Cmdtakedamage (rover);
Rpctakedamage (rover);
}
[ClientRpc]
public void Rpctakedamage(NetworkIdentity rover)
{
print ("RPC damage called");
GameObject roverGO = rover.gameObject;
WheelColliderController rwcc = roverGO.GetComponent<WheelColliderController>();
print (health);
health -= 60;
if (health <= 0)
{
print ("Setting false");
GameObject dpe = (GameObject) Instantiate (deathexplosion);
dpe.transform.position = roverGO.transform.position;
deathexplosion.GetComponent<ParticleSystem>().Play ();
roverGO.SetActive (false);
Destroy (clawId.gameObject);
}
}
[Command]
public void Cmdtakedamage(NetworkIdentity rover)
{
print ("CmdDamageCalled");
Rpctakedamage (rover);
}
Given your code snippet it's hard to tell what might be wrong. However the way you call the command and the rpc seems a bit strange.
"Commands" are ment to be called from clients but are executed on the server while "ClientRpcs" should be called from the server and are executed on the clients. Also note that you can only use "Command" and "ClientRpc" attributes inside a class that is derived from NetworkBehaviour
Your answer
Follow this Question
Related Questions
[UNET] Only spawn certain server objects on local client? 0 Answers
ClientRpc Function not being carried out on all clients in Unity3d c# 0 Answers
login to the server in unity c# 0 Answers
SyncListString not changing in a Command 0 Answers
Qos type ReliableFragmented channel, won't fragment our stream 2 Answers